Class: WWWJDic::Parser
- Inherits:
-
Object
- Object
- WWWJDic::Parser
- Defined in:
- lib/wwwjdic/parser.rb
Overview
This class is a simple utility that is used to parse and filter parameters for wwwjdic.
- Author
- Copyright
-
© 2014-2021 Marco Bresciani
- 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.
39 40 41 42 |
# File 'lib/wwwjdic/parser.rb', line 39 def initialize(args = {}) @parsers = {} ALL_PARAMS.each { |param| parsers[param] = args[param] } unless args.nil? end |
Instance Attribute Details
#parsers ⇒ Object (readonly)
Returns the value of attribute parsers.
37 38 39 |
# File 'lib/wwwjdic/parser.rb', line 37 def parsers @parsers end |
Instance Method Details
#parse(method = nil, params = nil) ⇒ Object
Provides the duck type for a generic parsing object.
45 46 47 48 49 |
# File 'lib/wwwjdic/parser.rb', line 45 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 |