Class: RateBeer::Style
- Inherits:
-
Object
- Object
- RateBeer::Style
- Extended by:
- URLs
- Defined in:
- lib/ratebeer/style.rb
Constant Summary
Constants included from URLs
URLs::BASE_URL, URLs::SEARCH_URL
Instance Attribute Summary collapse
-
#category ⇒ Object
Returns the value of attribute category.
Attributes included from Scraping
Class Method Summary collapse
-
.all_styles(include_hidden = false) ⇒ Array<RateBeer::Style>
Scrape all styles.
-
.data_keys ⇒ Object
Each key represents an item of data accessible for each beer, and defines dynamically a series of methods for accessing this data.
-
.hidden_styles ⇒ Array<Hash>
Scrape hidden style information.
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, #initialize, #inspect, nbsp, noko_doc, #page_count, #pagination?, #post_request, #symbolize_text, #to_s, #url
Instance Attribute Details
#category ⇒ Object
Returns the value of attribute category.
20 21 22 |
# File 'lib/ratebeer/style.rb', line 20 def category @category end |
Class Method Details
.all_styles(include_hidden = false) ⇒ Array<RateBeer::Style>
Scrape all styles.
RateBeer provides a styles landing page, with links through to info on each style listed thereon. This method scrapes style info with links to the more detailed pages.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ratebeer/style.rb', line 36 def all_styles(include_hidden = false) doc = Scraping.noko_doc(URI.join(BASE_URL, '/beerstyles/')) root = doc.at_css('div.container-fluid') categories = root.css('h3').map(&:text) style_node = root.css('.styleGroup') styles = style_node.flat_map.with_index do |list, i| list.css('a').map do |x| category = categories[i] Style.new(x['href'].split('/').last.to_i, name: x.text).tap do |s| s.category = category end end end if include_hidden styles + hidden_styles else styles end end |
.data_keys ⇒ Object
Each key represents an item of data accessible for each beer, and defines dynamically a series of methods for accessing this data.
10 11 12 13 14 15 |
# File 'lib/ratebeer/style.rb', line 10 def self.data_keys [:name, :description, :glassware, :beers] end |
.hidden_styles ⇒ Array<Hash>
Scrape hidden style information
RateBeer has a number of styles not accessible from the “beerstyles” landing page. This method scrapes these.
65 66 67 68 69 70 71 |
# File 'lib/ratebeer/style.rb', line 65 def hidden_styles hidden_ids = [40, 41, 57, 59, 66, 67, 68, 69, 70, 75, 83, 99, 104, 106, 116, 119, 120] hidden_ids.map do |id| Style.new(id) end end |