Class: Itch::Bundles

Inherits:
Object
  • Object
show all
Includes:
Request, RequireAuth, SimpleInspect
Defined in:
lib/itch/bundles.rb

Overview

Fetch bundles

Instance Method Summary collapse

Methods included from Request

#validate_response

Methods included from SimpleInspect

#exclude_inspection, #inspect, #pretty_print_instance_variables

Methods included from RequireAuth

#require_auth, #with_login

Constructor Details

#initialize(agent) ⇒ Bundles

Returns a new instance of Bundles.



17
18
19
# File 'lib/itch/bundles.rb', line 17

def initialize(agent)
  @agent = agent
end

Instance Method Details

#bundles_urlObject



40
41
42
# File 'lib/itch/bundles.rb', line 40

def bundles_url
  Itch::URL::BUNDLES
end

#listObject



21
22
23
24
25
26
27
28
29
# File 'lib/itch/bundles.rb', line 21

def list
  page =  do
    @agent.get(bundles_url)
  end

  page.css(".bundle_list table > tr").map do |row|
    parse_row(row)
  end
end

#parse_row(row) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/itch/bundles.rb', line 31

def parse_row(row)
  id = row.at_xpath("td[2]/a/@href").value.match(%r{^/b/(\d+)/})[1]
  vals = row.css("td").map(&:text)
  price = BigDecimal(vals[5].gsub(/[^\d.-]/, ""))
  earnings = BigDecimal(vals[6].gsub(/[\D-]/, ""))

  Bundle.new(id, vals[1], vals[4].to_i, price, earnings)
end