Class: Gravaty::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/gravaty/parser.rb

Overview

This class is a simple utility that is used to parse and filter parameters for gravaty.

Author

Marco Bresciani

Copyright

Copyright © 2013, 2014, 2015, 2016, 2017, 2018,

2019 Marco Bresciani

License

GNU General Public License version 3

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Parser

Returns a new instance of Parser.



35
36
37
38
39
40
# File 'lib/gravaty/parser.rb', line 35

def initialize(args = {})
  @parsers = Hash.new
  ALLOWED_PARAMS.each do |param|
    parsers[param] = args[param]
  end unless args.nil?
end

Instance Attribute Details

#parsersObject (readonly)

Returns the value of attribute parsers.



33
34
35
# File 'lib/gravaty/parser.rb', line 33

def parsers
  @parsers
end

Instance Method Details

#parse(method = nil, value = nil) ⇒ Object

Provides the duck type for a generic parsing object.



43
44
45
46
47
48
# File 'lib/gravaty/parser.rb', line 43

def parse(method = nil, value = nil)
  a_parser = nil
  a_parser = parsers[method.to_sym] unless method.nil? or
      parsers.nil?
  a_parser.parse value unless a_parser.nil?
end