Class: RateBeer::Beer::Alias

Inherits:
Object
  • Object
show all
Includes:
URLs
Defined in:
lib/ratebeer/beer/alias.rb

Overview

The Alias class.

RateBeer treats certain beers as aliases of another (e.g. Koenig Ludwig Weissbier - www.ratebeer.com/beer/konig-ludwig-weissbier/14945/) and provides a link to the “original” beer. This class is used to handle redirection where a beer is an alias.

Constant Summary collapse

ALIAS_SELECTOR =

CSS selector for container with alias information.

'.row.columns-container .col-sm-8'.freeze

Constants included from URLs

URLs::BASE_URL, URLs::SEARCH_URL

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

Constructor Details

#initialize(doc) ⇒ Alias

Create an Alias instance.

The Alias class deals with handling beers which may be aliases of others, and so requires redirection to the “proper” beer’s page.

Parameters:

  • document (Nokogiri::Doc)

    representing a RateBeer.com beer page



33
34
35
# File 'lib/ratebeer/beer/alias.rb', line 33

def initialize(doc)
  @doc = doc
end

Instance Method Details

#try_redirectObject

Redirects this beer to the “proper” beer page if it represents an alias of another beer.

This method returns a new doc value if the beer is an alias, or nil if not.



42
43
44
# File 'lib/ratebeer/beer/alias.rb', line 42

def try_redirect
  redirect_to_alias if aliased_beer?
end