Class: MWDictionaryAPI::Result
- Inherits:
-
Object
- Object
- MWDictionaryAPI::Result
- Defined in:
- lib/mw_dictionary_api/result.rb
Instance Attribute Summary collapse
-
#api_type ⇒ Object
readonly
Returns the value of attribute api_type.
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
-
#parser_class ⇒ Object
Returns the value of attribute parser_class.
-
#raw_response ⇒ Object
readonly
Returns the value of attribute raw_response.
-
#response_format ⇒ Object
readonly
Returns the value of attribute response_format.
-
#suggestions ⇒ Object
readonly
Returns the value of attribute suggestions.
-
#term ⇒ Object
readonly
Returns the value of attribute term.
Instance Method Summary collapse
-
#initialize(term, raw_response, api_type: "sd4", response_format: "xml", parser_class: Parsers::ResultParser) ⇒ Result
constructor
A new instance of Result.
- #parse! ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(term, raw_response, api_type: "sd4", response_format: "xml", parser_class: Parsers::ResultParser) ⇒ Result
Returns a new instance of Result.
10 11 12 13 14 15 16 17 18 |
# File 'lib/mw_dictionary_api/result.rb', line 10 def initialize(term, raw_response, api_type: "sd4", response_format: "xml", parser_class: Parsers::ResultParser) @term = term @raw_response = raw_response @api_type = api_type @response_format = response_format @parser_class = parser_class parse! end |
Instance Attribute Details
#api_type ⇒ Object (readonly)
Returns the value of attribute api_type.
7 8 9 |
# File 'lib/mw_dictionary_api/result.rb', line 7 def api_type @api_type end |
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
7 8 9 |
# File 'lib/mw_dictionary_api/result.rb', line 7 def entries @entries end |
#parser_class ⇒ Object
Returns the value of attribute parser_class.
6 7 8 |
# File 'lib/mw_dictionary_api/result.rb', line 6 def parser_class @parser_class end |
#raw_response ⇒ Object (readonly)
Returns the value of attribute raw_response.
7 8 9 |
# File 'lib/mw_dictionary_api/result.rb', line 7 def raw_response @raw_response end |
#response_format ⇒ Object (readonly)
Returns the value of attribute response_format.
7 8 9 |
# File 'lib/mw_dictionary_api/result.rb', line 7 def response_format @response_format end |
#suggestions ⇒ Object (readonly)
Returns the value of attribute suggestions.
7 8 9 |
# File 'lib/mw_dictionary_api/result.rb', line 7 def suggestions @suggestions end |
#term ⇒ Object (readonly)
Returns the value of attribute term.
7 8 9 |
# File 'lib/mw_dictionary_api/result.rb', line 7 def term @term end |
Instance Method Details
#parse! ⇒ Object
20 21 22 23 24 25 |
# File 'lib/mw_dictionary_api/result.rb', line 20 def parse! parser = parser_class.new(api_type: api_type, response_format: response_format) attributes = parser.parse(Nokogiri::XML(raw_response)) @entries = attributes[:entries] @suggestions = attributes[:suggestions] end |
#to_hash ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/mw_dictionary_api/result.rb', line 27 def to_hash { term: term, entries: entries, suggestions: suggestions } end |