Class: Itch::Bundles
- Inherits:
-
Object
- Object
- Itch::Bundles
- Includes:
- Request, RequireAuth, SimpleInspect
- Defined in:
- lib/itch/bundles.rb
Overview
Fetch bundles
Instance Method Summary collapse
- #bundles_url ⇒ Object
-
#initialize(agent) ⇒ Bundles
constructor
A new instance of Bundles.
- #list ⇒ Object
- #parse_row(row) ⇒ Object
Methods included from Request
Methods included from SimpleInspect
#exclude_inspection, #inspect, #pretty_print_instance_variables
Methods included from RequireAuth
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_url ⇒ Object
40 41 42 |
# File 'lib/itch/bundles.rb', line 40 def bundles_url Itch::URL::BUNDLES end |
#list ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/itch/bundles.rb', line 21 def list page = with_login 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 |