lib/ratebeer/search.rb
# Process breweries table returned in search.
#
# The breweries table (if returned) consists of a series of rows each
# containing two cells: the first is the name (and hyperlink) to the
# brewery; and the second is the full location of the brewery.
#
# @param [Nokogiri::XML::Element] table An HTML table containing breweries
#   information
# @return [Hash{Symbol, String}] Brewery data, including name, location,
#   url and ID
#
Process breweries table returned in search.
The breweries table (if returned) consists of a series of rows each
containing two cells: the first is the name (and hyperlink) to the
brewery; and the second is the full location of the brewery.
Process breweries table returned in search . The breweries table ( if returned ) consists of a series of rows each containing two cells : the first is the name ( and hyperlink ) to the brewery ; and the second is the full location of the brewery .
def process_breweries_table(table)
      table.css('tr').map do |row|
        result = [:id, :name, :location, :url].zip([nil]).to_h
        result[:name], result[:location] = row.element_children.map do |x|
          fix_characters(x.text)
        end
        result[:url] = row.at_css('a')['href']
        result[:id]  = result[:url].split('/').last.to_i
        Brewery::Brewery.new(result[:id], name: result[:name])
      end
    end
def process_breweries_table ( table ) table . css ( 'tr' ) . map do | row | result = [ :id , :name , :location , :url ] . zip ( [ nil ] ) . to_h result [ :name ] , result [ :location ] = row . element_children . map do | x | fix_characters ( x . text ) end result [ :url ] = row . at_css ( 'a' ) [ 'href' ] result [ :id ] = result [ :url ] . split ( '/' ) . last . to_i Brewery :: Brewery . new ( result [ :id ] , name : result [ :name ] ) end end
Process breweries table returned in search.
Process breweries table returned in search .
Brewery data, including name, location, url and ID
Brewery data including name location url and ID
Hash{Symbol, String}
table
table An HTML table containing breweries information
table An HTML table containing breweries information