class Eventick::ParamsParser
Constants
- LAST_RESOURCE_REGEX
- RESOURCE_KEYS
Public Class Methods
new(resource, params={})
click to toggle source
# File lib/eventick/params_parser.rb, line 6 def initialize(resource, params={}) @resource = resource @params = params def @params.with_stringified_keys Hash[self.map{ |k, v| [k.to_s, v] }] end end
Public Instance Methods
perform()
click to toggle source
# File lib/eventick/params_parser.rb, line 15 def perform if missing_arguments raise UnmatchableParams, "Missing arguments: #{missing_arguments}." end if @params.empty? @resource.gsub(LAST_RESOURCE_REGEX, "") else stringified_hash = @params.with_stringified_keys replace_resource_fields stringified_hash end end
Private Instance Methods
available_params()
click to toggle source
# File lib/eventick/params_parser.rb, line 39 def available_params @params.with_stringified_keys.keys.flatten end
missing_arguments()
click to toggle source
# File lib/eventick/params_parser.rb, line 29 def missing_arguments if (missing = (params_needed - available_params)).length > 1 @missing_arguments = missing end end
params_needed()
click to toggle source
# File lib/eventick/params_parser.rb, line 35 def params_needed @params_needed ||= @resource.scan(RESOURCE_KEYS).flatten end
replace_resource_fields(stringified_hash)
click to toggle source
# File lib/eventick/params_parser.rb, line 43 def replace_resource_fields(stringified_hash) result = @resource.gsub(RESOURCE_KEYS, stringified_hash) result.gsub(/:/ , '').gsub(/\/$/ , '') end