Module: SpitterMethods::InstanceMethods

Defined in:
lib/rakumarket/spitter.rb

Instance Method Summary collapse

Instance Method Details

#initialize(params) ⇒ Object

Initialize the parser with a parameters



76
77
78
# File 'lib/rakumarket/spitter.rb', line 76

def initialize(params)
  @params = params
end

#paramsObject



80
81
82
# File 'lib/rakumarket/spitter.rb', line 80

def params
  @params ||= {}
end

#parseObject



84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/rakumarket/spitter.rb', line 84

def parse
  request_params = {}
  self.class.rules.each do |target, (key, delegate, plural)|
    if @params.has_key?(target)
      if plural
        request_params.merge!(delegate.parse(@params[target]))
      else
        request_params[key] = parse_result(@params[target], delegate)
      end
    end
  end
  request_params
end