lib/ratebeer/search.rb
def process_beer_row(row)
      result = [:id, :name, :score, :ratings, :url].zip([nil]).to_h
      content = row.element_children.map { |x| fix_characters(x.text) }
      result[:name] = row.element_children.first.at_css('a').text
      result[:score], result[:ratings] = content.values_at(3, 4)
                                                .map do |n|
        n.nil? || n.empty? ? nil : n.to_i
      end
      result[:url] = row.at_css('a')['href']
      result[:id]  = result[:url].split('/').last.to_i
      b = Beer::Beer.new(result[:id], name: result[:name])
      b.brewery.name if @scrape_beer_brewers
      b
    end
# Processes one row from a beer table.
Processes one row from a beer table.
Processes one row from a beer table .
def process_beer_row(row)
      result = [:id, :name, :score, :ratings, :url].zip([nil]).to_h
      content = row.element_children.map { |x| fix_characters(x.text) }
      result[:name] = row.element_children.first.at_css('a').text
      result[:score], result[:ratings] = content.values_at(3, 4)
                                                .map do |n|
        n.nil? || n.empty? ? nil : n.to_i
      end
      result[:url] = row.at_css('a')['href']
      result[:id]  = result[:url].split('/').last.to_i
      b = Beer::Beer.new(result[:id], name: result[:name])
      b.brewery.name if @scrape_beer_brewers
      b
    end
def process_beer_row ( row ) result = [ :id , :name , :score , :ratings , :url ] . zip ( [ nil ] ) . to_h content = row . element_children . map { | x | fix_characters ( x . text ) } result [ :name ] = row . element_children . first . at_css ( 'a' ) . text result [ :score ] , result [ :ratings ] = content . values_at ( 3 , 4 ) . map do | n | n . nil? || n . empty? ? nil : n . to_i end result [ :url ] = row . at_css ( 'a' ) [ 'href' ] result [ :id ] = result [ :url ] . split ( '/' ) . last . to_i b = Beer :: Beer . new ( result [ :id ] , name : result [ :name ] ) b . brewery . name if @scrape_beer_brewers b end
Processes one row from a beer table.
Processes one row from a beer table .
row