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
- #to_json ⇒ Object
Constructor Details
#initialize(term, raw_response, api_type: "sd4", response_format: "xml", parser_class: Parsers::ResultParser) ⇒ Result
Returns a new instance of Result.
13 14 15 16 17 18 19 20 21 |
# File 'lib/mw_dictionary_api/result.rb', line 13 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.
10 11 12 |
# File 'lib/mw_dictionary_api/result.rb', line 10 def api_type @api_type end |
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
10 11 12 |
# File 'lib/mw_dictionary_api/result.rb', line 10 def entries @entries end |
#parser_class ⇒ Object
Returns the value of attribute parser_class.
9 10 11 |
# File 'lib/mw_dictionary_api/result.rb', line 9 def parser_class @parser_class end |
#raw_response ⇒ Object (readonly)
Returns the value of attribute raw_response.
10 11 12 |
# File 'lib/mw_dictionary_api/result.rb', line 10 def raw_response @raw_response end |
#response_format ⇒ Object (readonly)
Returns the value of attribute response_format.
10 11 12 |
# File 'lib/mw_dictionary_api/result.rb', line 10 def response_format @response_format end |
#suggestions ⇒ Object (readonly)
Returns the value of attribute suggestions.
10 11 12 |
# File 'lib/mw_dictionary_api/result.rb', line 10 def suggestions @suggestions end |
#term ⇒ Object (readonly)
Returns the value of attribute term.
10 11 12 |
# File 'lib/mw_dictionary_api/result.rb', line 10 def term @term end |
Instance Method Details
#parse! ⇒ Object
23 24 25 26 27 28 |
# File 'lib/mw_dictionary_api/result.rb', line 23 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
30 31 32 33 34 35 36 |
# File 'lib/mw_dictionary_api/result.rb', line 30 def to_hash { term: term, entries: entries, suggestions: suggestions } end |
#to_json ⇒ Object
38 39 40 |
# File 'lib/mw_dictionary_api/result.rb', line 38 def to_json to_hash.to_json end |