Class: BingSearchClient::Result

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body:) ⇒ Result

Returns a new instance of Result.



5
6
7
8
# File 'lib/bing_search_client/result.rb', line 5

def initialize(body:)
  @body = body
  @expanded_url = nil
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



3
4
5
# File 'lib/bing_search_client/result.rb', line 3

def body
  @body
end

#expanded_urlObject (readonly)

Returns the value of attribute expanded_url.



3
4
5
# File 'lib/bing_search_client/result.rb', line 3

def expanded_url
  @expanded_url
end

Class Method Details

.build_from_array_response(raw_response:) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/bing_search_client/result.rb', line 10

def self.build_from_array_response(raw_response:)
  raw_response.map do |result_json_response|
    new(body: result_json_response).tap do |result|
      result.expand_url!
    end
  end
end

Instance Method Details

#expand_url!Object

Instance method to get the real url insted of the url bing



19
20
21
22
23
# File 'lib/bing_search_client/result.rb', line 19

def expand_url!
  bing_url = URI(body[:url])
  parsed_query = CGI::parse(bing_url.query)
  @expanded_url = parsed_query['r'].first
end