Sha256: 2654500fc9d1b7f1a868e787634b40afe01748601410694c30dc74d5fc50f4fc
Contents?: true
Size: 1.58 KB
Versions: 1
Compression:
Stored size: 1.58 KB
Contents
require 'open-uri' require 'nokogiri' class Brewery_Fetcher def self.query_api(api_query) returned_request = Nokogiri::HTML(open(api_query)) breweries = [] #we gotta use something called xpath? returned_request.xpath("//location").each do |location| brewery = { :id => location.xpath("child::id").text.to_i, :name => location.xpath("child::name").text, :street_address => location.xpath("child::street").text, :phone => location.xpath("child::phone").text } #add brewery to breweries breweries << brewery end return breweries end #change to self.fetch_score_info def self.fetch_score_info(score_request) returned_scores = Nokogiri::HTML(open(score_request)) #brewery score profile score_location = returned_scores.xpath("//location/*") if (score_location.xpath("//overall").text.to_i == 0) #puts "fetcher error" score_profile = nil else #puts "#{score_location.xpath("//overall").text}" score_profile = { #overall_score, selection, service, atmosphere, food, review_count :overall_score => score_location.xpath("//overall").text.to_f.round(1), :selection => score_location.xpath("//selection").text.to_f.round(2), :service => score_location.xpath("//service").text.to_f.round(2), :atmosphere => score_location.xpath("//atmosphere").text.to_f.round(2), :review_count => score_location.xpath("//reviewcount").text.to_i, :food=>score_location.xpath("//food").text.to_f.round(2) } score_profile end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
Brew_Finder-0.1.1 | lib/Brew_Finder/brewery_fetcher.rb |