lib/ratebeer/search.rb
def run_search
      @beers, @breweries = nil
      tables             = doc.css('h2').map(&:text).zip(doc.css('table'))
      beers, breweries   = nil
      tables.each do |(heading, table)|
        case heading
        when 'brewers'
          @breweries = process_breweries_table(table)
        when 'beers'
          @beers = process_beers_table(table)
        end
      end

      # RateBeer is inconsistent with searching for IPAs. If IPA is in the name
      # of the beer, replace IPA with India Pale Ale, and add the additional
      # results to these results.
      if query.downcase.include?(' ipa')
        alt_query = query.downcase.gsub(' ipa', ' india pale ale')
        extra_beers = self.class.new(alt_query).run_search.beers
        @beers = ((@beers || []) + (extra_beers || [])).uniq
      end
      self
    end
# Search RateBeer for beers, brewers, etc.
#
# The search results page contains a series of tables each of which has the
# "results" class, containing data of matching brewers, beers, and places
# in that order. Only brewers and beers are extracted.
#
# @return [Hash] Results of the search, broken into breweries and beers,
#                with the attributes of these results contained therein.
#
Search RateBeer for beers, brewers, etc.
The search results page contains a series of tables each of which has the
"results" class, containing data of matching brewers, beers, and places
in that order. Only brewers and beers are extracted.
Search RateBeer for beers brewers etc . The search results page contains a series of tables each of which has the " results " class containing data of matching brewers beers and places in that order . Only brewers and beers are extracted .
def run_search
      @beers, @breweries = nil
      tables             = doc.css('h2').map(&:text).zip(doc.css('table'))
      beers, breweries   = nil
      tables.each do |(heading, table)|
        case heading
        when 'brewers'
          @breweries = process_breweries_table(table)
        when 'beers'
          @beers = process_beers_table(table)
        end
      end
      if query.downcase.include?(' ipa')
        alt_query = query.downcase.gsub(' ipa', ' india pale ale')
        extra_beers = self.class.new(alt_query).run_search.beers
        @beers = ((@beers || []) + (extra_beers || [])).uniq
      end
      self
    end
def run_search @beers , @breweries = nil tables = doc . css ( 'h2' ) . map ( & :text ) . zip ( doc . css ( 'table' ) ) beers , breweries = nil tables . each do | ( heading , table ) | case heading when 'brewers' @breweries = process_breweries_table ( table ) when 'beers' @beers = process_beers_table ( table ) end end if query . downcase . include? ( ' ipa' ) alt_query = query . downcase . gsub ( ' ipa' , ' india pale ale' ) extra_beers = self . class . new ( alt_query ) . run_search . beers @beers = ( ( @beers || [ ] ) + ( extra_beers || [ ] ) ) . uniq end self end
Search RateBeer for beers, brewers, etc.
Search RateBeer for beers brewers etc .
# RateBeer is inconsistent with searching for IPAs. If IPA is in the name # of the beer, replace IPA with India Pale Ale, and add the additional # results to these results.
Results of the search, broken into breweries and beers, with the attributes of these results contained therein.
Results of the search broken into breweries and beers with the attributes of these results contained therein .
Hash