Class: WWWJDic::Parser

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

Overview

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

Author

Marco Bresciani

Copyright

© 2014-2021 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.



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

#parsersObject (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