Class: Eventick::ParamsParser

Inherits:
Object
  • Object
show all
Defined in:
lib/eventick/params_parser.rb

Constant Summary collapse

RESOURCE_KEYS =
/(?<=:)(.\w+)/
LAST_RESOURCE_REGEX =
/\/:(.\w+)$/

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource, params = {}) ⇒ ParamsParser

Returns a new instance of ParamsParser.



6
7
8
9
10
11
12
13
# 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

Class Method Details

.with_stringified_keysObject



10
11
12
# File 'lib/eventick/params_parser.rb', line 10

def @params.with_stringified_keys
  Hash[self.map{ |k, v| [k.to_s, v] }]
end

Instance Method Details

#performObject



15
16
17
18
19
20
21
22
23
24
25
26
# 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