class MWDictionaryAPI::Result
Attributes
api_type[R]
entries[R]
parser_class[RW]
raw_response[R]
response_format[R]
suggestions[R]
term[R]
Public Class Methods
new(term, raw_response, api_type: "sd4", response_format: "xml", parser_class: Parsers::ResultParser)
click to toggle source
# 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
Public Instance Methods
parse!()
click to toggle source
# 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()
click to toggle source
# File lib/mw_dictionary_api/result.rb, line 30 def to_hash { term: term, entries: entries, suggestions: suggestions } end
to_json()
click to toggle source
# File lib/mw_dictionary_api/result.rb, line 38 def to_json to_hash.to_json end