class BeerMe::Beer
Attributes
name[RW]
reviews[RW]
score[RW]
style[RW]
Public Class Methods
all()
click to toggle source
# File lib/beer_me/beer.rb, line 11 def self.all @@beers end
new()
click to toggle source
# File lib/beer_me/beer.rb, line 7 def initialize @@beers << self end
scrape_beers_site()
click to toggle source
# File lib/beer_me/beer.rb, line 15 def self.scrape_beers_site #obtains the page from ratebeer as nokogiri elements doc = Nokogiri::HTML(open("https://www.ratebeer.com/Ratings/TopOfTheMonth.asp")) #List the beers of the month #Use 'tr' to get the rows that contains the info for each beer #each row is an array of items #the name of the beer is the [1] element beer_rows = doc.css('tr') beer_rows.each_with_index do |row, i| #since the iteration will bring back the first row and that row has no info we want to skip the first one if i != 0 beer = BeerMe::Beer.new beer.name = row.css('td')[1].text beer.style = row.css('td')[4].text beer.reviews = row.css('td')[3].text beer.score = row.css('td')[2].text end end end