Class: BOSSMan::ResultSet

Inherits:
BaseValueObject show all
Defined in:
lib/bossman/resultset.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseValueObject

#set_parameter, #to_json, #to_yaml

Constructor Details

#initialize(response) ⇒ ResultSet

Returns a new instance of ResultSet.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/bossman/resultset.rb', line 4

def initialize(response)
  @response = response

  @response["ysearchresponse"].each do |key, value|
    if key.include? "resultset_spell"
      set_parameter("suggestion", @response["ysearchresponse"]["resultset_spell"][0]["suggestion"])
    elsif key.include? "resultset"
      results = Array.new
      response["ysearchresponse"][key].each { |result| results << Result.new(result) }
      set_parameter("results", results)
    else
      set_parameter(key, value)
    end        
  end
end

Class Method Details

._load(string) ⇒ Object



28
29
30
# File 'lib/bossman/resultset.rb', line 28

def self._load(string)
  ResultSet.new(ActiveSupport::JSON.decode(string))
end

Instance Method Details

#_dump(level) ⇒ Object



24
25
26
# File 'lib/bossman/resultset.rb', line 24

def _dump(level)
  @response.to_json
end

#to_xmlObject Also known as: to_s



20
21
22
# File 'lib/bossman/resultset.rb', line 20

def to_xml
  @response['ysearchresponse'].to_xml(:root => 'resultset')
end