Class: Lita::Handlers::OnewheelBeerUntappdLib

Inherits:
OnewheelBeerBase
  • Object
show all
Defined in:
lib/lita/handlers/onewheel_beer_untappd_lib.rb

Instance Method Summary collapse

Instance Method Details

#parse_response(response) ⇒ Object

This is the worker bee- decoding the html into our “standard” document. Future implementations could simply override this implementation-specific code to help this grow more widely.

[View source]

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/lita/handlers/onewheel_beer_untappd_lib.rb', line 12

def parse_response(response)
  Lita.logger.debug 'parse_response started.'

  gimme_what_you_got = {}
  noko = Nokogiri.HTML response
  noko.css('div.beer-details').each do |beer_node|
    # beer_node = beer_node.css('div#section_217106141')
    name_n_tap = beer_node.css('h5 a').first.children.to_s
    short_desc = beer_node.css('h5 em').first.children.to_s
    brewery = beer_node.css('h6 a').first.children.to_s
    abv_node = beer_node.css('h6 span').first.children.to_s

    # Lita.logger.info("NnT: #{name_n_tap}")
    /^(?<tap>\d)\.\s*(?<beer_name>.*)/ =~ name_n_tap
    # tap = name_n_tap[/^\d+/]
    next if tap.nil?
    # print "name_n_tap #{name_n_tap}"
    # beer_name = name_n_tap[/[^\..]+$/].strip
    abv = abv_node[/^\d+\.\d+/]
    beer_desc = short_desc

    # full_text_search = "#{tap.sub /\d+/, ''} #{brewery} #{beer_name} #{beer_desc.to_s.gsub /\d+\.*\d*%*/, ''}"
    # prices = get_prices(beer_node)

    gimme_what_you_got[tap] = {
        # type: tap_type,
        # remaining: remaining,
        brewery: brewery.to_s,
        name: beer_name.to_s,
        desc: beer_desc.to_s,
        abv: abv.to_f
        # prices: prices,
        # price: prices[1][:cost],
        # search: full_text_search
    }
  end
  gimme_what_you_got
end