Skip to content
This repository has been archived by the owner on Dec 15, 2018. It is now read-only.

Commit

Permalink
Minor readability changes
Browse files Browse the repository at this point in the history
  • Loading branch information
John Pignata committed Dec 28, 2009
1 parent 02f5f2f commit 0c980a1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
32 changes: 17 additions & 15 deletions lib/bossman/base_value_object.rb
@@ -1,20 +1,22 @@
module BOSSMan
class BaseValueObject
def set_parameter(key, value)
instance_variable_set("@#{key}", value)
end

def to_yaml
@response.to_yaml
end

def set_parameter(key, value)
instance_variable_set("@#{key}", value)
end

def method_missing(*args)
method = args.first
instance_variable_get("@#{method}")
end

def to_json
ActiveSupport::JSON.encode(@response)
end
def method_missing(*args)
method = args.first
instance_variable_get("@#{method}")
end
def to_yaml
@response.to_yaml
end

def to_json
ActiveSupport::JSON.encode(@response)
end
end
end
13 changes: 6 additions & 7 deletions lib/bossman/result_set.rb
Expand Up @@ -3,11 +3,12 @@ class ResultSet < BaseValueObject

def initialize(response)
@response = response
@ysearchresponse = response["ysearchresponse"]
process_response
end

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

def _dump(level)
Expand All @@ -22,7 +23,7 @@ def self._load(string)

private
def process_response
@response["ysearchresponse"].each do |key, value|
@ysearchresponse.each do |key, value|
case key
when "resultset_spell"
process_spelling_result
Expand All @@ -35,14 +36,12 @@ def process_response
end

def process_spelling_result
set_parameter("suggestion", @response["ysearchresponse"]["resultset_spell"].first["suggestion"])
suggestion = @ysearchresponse["resultset_spell"].first["suggestion"]
set_parameter("suggestion", suggestion)
end

def process_resultset(key)
results = @response["ysearchresponse"][key].map do |result|
Result.new(result)
end

results = @ysearchresponse[key].map { |result| Result.new(result) }
set_parameter("results", results)
end
end
Expand Down

0 comments on commit 0c980a1

Please sign in to comment.