class Hopcat::Api::Draft
Attributes
location[RW]
Public Class Methods
new()
click to toggle source
# File lib/hopcat/api/draft.rb, line 10 def initialize @location = 'http://www.hopcat.com/tap/broad-ripple' end
Public Instance Methods
item_abv(item)
click to toggle source
# File lib/hopcat/api/draft.rb, line 64 def item_abv(item) item.css('div.views-field-field-beer-abv div').text.gsub(/[()]/,'').strip end
item_brewery(item)
click to toggle source
# File lib/hopcat/api/draft.rb, line 56 def item_brewery(item) item.css('div.views-field-field-brewery div').text.strip end
item_list_category(item_list)
click to toggle source
# File lib/hopcat/api/draft.rb, line 34 def item_list_category(item_list) item_list.css('h3')[0].text end
item_lists()
click to toggle source
# File lib/hopcat/api/draft.rb, line 29 def item_lists page = Nokogiri::HTML( open(location) ) page.css('div.view-content div.view-order-beers') end
item_location(item)
click to toggle source
# File lib/hopcat/api/draft.rb, line 60 def item_location(item) item.css('div.views-field-field-city-state-country div').text.strip end
item_style(item)
click to toggle source
# File lib/hopcat/api/draft.rb, line 73 def item_style(item) style = item.css('div.views-field-body div').text.strip style = strip_nbsp(style) if style.lines.size > 1 style = style.lines.first end style.strip end
item_title(item)
click to toggle source
# File lib/hopcat/api/draft.rb, line 52 def item_title(item) item.css('div.views-field-title span').text.strip end
item_to_hash(item)
click to toggle source
# File lib/hopcat/api/draft.rb, line 42 def item_to_hash(item) { title: item_title(item), brewery: item_brewery(item), location: item_location(item), abv: item_abv(item), style: item_style(item) } end
items(item_list)
click to toggle source
# File lib/hopcat/api/draft.rb, line 38 def items(item_list) item_list.css('li.views-row') end
list()
click to toggle source
# File lib/hopcat/api/draft.rb, line 14 def list results = { drafts: [] } item_lists.each do |a_list| category = item_list_category(a_list) items(a_list).each do |item| beer_hash = item_to_hash(item) beer_hash[:category] = category results[:drafts] << beer_hash end end results end
strip_nbsp(str)
click to toggle source
# File lib/hopcat/api/draft.rb, line 68 def strip_nbsp(str) nbsp = Nokogiri::HTML(" ").text str.gsub(nbsp, '') end