Class: Gravaty::Parser
- Inherits:
-
Object
- Object
- Gravaty::Parser
- Defined in:
- lib/gravaty/parser.rb
Overview
This class is a simple utility that is used to parse and filter parameters for gravaty.
- Author
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
-
#parsers ⇒ Object
readonly
Returns the value of attribute parsers.
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ Parser
constructor
A new instance of Parser.
-
#parse(method = nil, params = nil) ⇒ Object
Provides the duck type for a generic parsing object.
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
#parsers ⇒ Object (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 |