Class: RateBeer::Location

Inherits:
Object
  • Object
show all
Includes:
Scraping, URLs
Defined in:
lib/ratebeer/location.rb

Direct Known Subclasses

Country, Region

Constant Summary

Constants included from URLs

URLs::BASE_URL, URLs::SEARCH_URL

Instance Attribute Summary

Attributes included from Scraping

#id

Class Method Summary collapse

Instance Method Summary collapse

Methods included from URLs

#beer_url, #brewery_beers_url, #brewery_url, #country_url, #region_url, #review_url, #style_beers_url, #style_url

Methods included from Scraping

#==, #fix_characters, #full_details, #id_from_link, included, #inspect, nbsp, noko_doc, #page_count, #pagination?, #post_request, #symbolize_text, #to_s

Constructor Details

#initialize(id, location_type: nil, name: nil, **options) ⇒ Location

Initialize a RateBeer::Location instance.

Locations may be either Regions or Countries. This must be specified to the constructor.

Parameters:

  • id (Integer)

    ID# for this location

  • location_type (Symbol) (defaults to: nil)

    Symbol representing either country or region

  • name (String) (defaults to: nil)

    Name of this location



26
27
28
29
30
31
32
33
# File 'lib/ratebeer/location.rb', line 26

def initialize(id, location_type: nil, name: nil, **options)
  super
  if location_type.nil? || ![:country, :region].include?(location_type)
    raise ArgumentError.new('location_type must be supplied and must be '\
                            'either country or region')
  end
  @location_type = location_type
end

Class Method Details

.data_keysObject

Keys for fields scraped on RateBeer



8
9
10
11
12
# File 'lib/ratebeer/location.rb', line 8

def self.data_keys
  [:name,
   :num_breweries,
   :breweries]
end

Instance Method Details

#docObject



35
36
37
38
39
40
41
# File 'lib/ratebeer/location.rb', line 35

def doc
  unless instance_variable_defined?('@doc')
    @doc = noko_doc(url)
    validate_location
  end
  @doc
end