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



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/three_usage/parser.rb', line 26

def print_table
  printf "+-"
  printf "-" * 40
  printf "-+-"
  printf "-" * 20
  printf "-+-"
  printf "-" * 20
  printf "-+\n"
  
  @usage_blocks.each do |usage_block|
    printf("| %40s | %20s | %20s |\n", usage_block.description, usage_block.remaining, usage_block.expires_at)
  end

  printf "+-"
  printf "-" * 40
  printf "-+-"
  printf "-" * 20
  printf "-+-"
  printf "-" * 20
  printf "-+\n"
end

#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