Class: ThreeUsage::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/three_usage/parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doc) ⇒ Parser

Returns a new instance of Parser.



7
8
9
10
11
12
13
14
15
16
# File 'lib/three_usage/parser.rb', line 7

def initialize(doc)
  @usage_blocks = []
  rows = doc.search(".my3RemainBonusFreeUnitsTable").search("tr")
  rows.each do |row|
    cells = row.search("td")
    usage_blocks << UsageBlock.new(:description => cells[0].inner_html.gsub(/\t/, '').strip,
      :remaining => cells[1].inner_html.gsub(/\t/, '').strip,
      :expires_at => cells[2].inner_html.gsub(/\t/, '').strip)
  end
end

Instance Attribute Details

#usage_blocksObject

Returns the value of attribute usage_blocks.



6
7
8
# File 'lib/three_usage/parser.rb', line 6

def usage_blocks
  @usage_blocks
end

Instance Method Details

#remaining_three_quotaObject



22
23
24
# File 'lib/three_usage/parser.rb', line 22

def remaining_three_quota
  three_usage_blocks.inject(0){|sum,item| sum + item.remaining}
end

#three_usage_blocksObject



18
19
20
# File 'lib/three_usage/parser.rb', line 18

def three_usage_blocks
  @usage_blocks.delete_if {|b| b.block_type != :three}
end