lib/ratebeer/location.rb
def scrape_breweries
      brewery_info = doc.css('#tabs table')
      @breweries = brewery_info.flat_map.with_index do |tbl, i|
        status = i == 0 ? 'Active' : 'Out of Business'

        tbl.css('tr').drop(1).flat_map do |row|
          cells = row.css('td')
          next if cells.empty?
          id       = cells[0].at_css('a')['href'].split('/').last.to_i
          name     = cells[0].text.split('-').first.strip
          location = cells[0].text
                             .split('-')
                             .last
                             .sub('(Out of Business)', '')
                             .strip
          type = cells[1].text.strip
          established = status == 'Active' ? cells[3].text.to_i : nil
          Brewery::Brewery.new(id,
                               name:        name,
                               location:    location,
                               type:        type,
                               established: established,
                               status:      status)
        end
      end
    end
# Keys for fields scraped on RateBeer
Keys for fields scraped on RateBeer
Keys for fields scraped on RateBeer
def scrape_breweries
      brewery_info = doc.css('#tabs table')
      @breweries = brewery_info.flat_map.with_index do |tbl, i|
        status = i == 0 ? 'Active' : 'Out of Business'
        tbl.css('tr').drop(1).flat_map do |row|
          cells = row.css('td')
          next if cells.empty?
          id       = cells[0].at_css('a')['href'].split('/').last.to_i
          name     = cells[0].text.split('-').first.strip
          location = cells[0].text
                             .split('-')
                             .last
                             .sub('(Out of Business)', '')
                             .strip
          type = cells[1].text.strip
          established = status == 'Active' ? cells[3].text.to_i : nil
          Brewery::Brewery.new(id,
                               name:        name,
                               location:    location,
                               type:        type,
                               established: established,
                               status:      status)
        end
      end
    end
def scrape_breweries brewery_info = doc . css ( '#tabs table' ) @breweries = brewery_info . flat_map . with_index do | tbl , i | status = i == 0 ? 'Active' : 'Out of Business' tbl . css ( 'tr' ) . drop ( 1 ) . flat_map do | row | cells = row . css ( 'td' ) next if cells . empty? id = cells [ 0 ] . at_css ( 'a' ) [ 'href' ] . split ( '/' ) . last . to_i name = cells [ 0 ] . text . split ( '-' ) . first . strip location = cells [ 0 ] . text . split ( '-' ) . last . sub ( '(Out of Business)' , '' ) . strip type = cells [ 1 ] . text . strip established = status == 'Active' ? cells [ 3 ] . text . to_i : nil Brewery :: Brewery . new ( id , name : name , location : location , type : type , established : established , status : status ) end end end
Keys for fields scraped on RateBeer
Keys for fields scraped on RateBeer