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

rubocop:disable Style/AsciiComments

Copyright

Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Marco Bresciani

rubocop:enable Style/AsciiComments

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.



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

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

Instance Attribute Details

#parsersObject (readonly)

Returns the value of attribute parsers.



41
42
43
# File 'lib/gravaty/parser.rb', line 41

def parsers
  @parsers
end

Instance Method Details

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

Provides the duck type for a generic parsing object.



49
50
51
52
53
# File 'lib/gravaty/parser.rb', line 49

def parse(method = nil, params = nil)
  a_parser = nil
  a_parser = parsers[method.to_sym] unless method.nil? || parsers.nil?
  a_parser&.parse params
end