Class: RuBing::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/rubing.rb

Constant Summary collapse

REQUIRED_ATTRIBUTES =
%w{title description url}

Instance Method Summary collapse

Constructor Details

#initialize(result_hash) ⇒ Result

Returns a new instance of Result.



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/rubing.rb', line 146

def initialize(result_hash)
  @data = result_hash
  result_hash.each_pair do |key, value|
    next if key == "SearchTags" || key == "DeepLinks" # not sure why this is returned. I don't want it  :p
    begin
      instance_eval(<<-EOS, __FILE__, __LINE__)
        def #{Result.rubyize(key)}
          #{value.dump}
        end
      EOS
    rescue Exception => e
      puts "Bad Key: '#{key}' #{e.message}"
      puts result_hash.inspect
    end
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object

So in some unknown situations Bing does not return some attributes!

Raises:

  • (NoMethodError)


164
165
166
167
# File 'lib/rubing.rb', line 164

def method_missing(method_name, *args, &block)
  return "" if REQUIRED_ATTRIBUTES.include?(method_name.to_s)
  raise NoMethodError
end

Instance Method Details

#dataObject



169
170
171
# File 'lib/rubing.rb', line 169

def data
  @data
end