Class: ThreeUKUsage

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url = 'https://www.three.co.uk/New_My3/' + 'Data_allowance?id=My3_DataAllowanceHeading') ⇒ ThreeUKUsage

Returns a new instance of ThreeUKUsage.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/threeuk_usage.rb', line 15

def initialize(url='https://www.three.co.uk/New_My3/' + 
                    'Data_allowance?id=My3_DataAllowanceHeading')

  agent = Mechanize.new

  page  = agent.get url
  page2 = agent.click(page.links[0])
  page3 = agent.click(page2.link_with(text: " Check your data allowance."))

  cols = page3.css('.balance tbody/tr[2]/td/text()').map {|x| x.to_s.strip}
  @expires = Date.strptime(cols[1][/\d+\/\d+\/\d+$/], "%d/%m/%y")
  @remaining = cols[2].to_i

end

Instance Attribute Details

#expiresObject (readonly)

Returns the value of attribute expires.



13
14
15
# File 'lib/threeuk_usage.rb', line 13

def expires
  @expires
end

#remainingObject (readonly)

Returns the value of attribute remaining.



13
14
15
# File 'lib/threeuk_usage.rb', line 13

def remaining
  @remaining
end

Instance Method Details

#to_hObject



30
31
32
# File 'lib/threeuk_usage.rb', line 30

def to_h()
  {expires: @expires, remaining: @remaining}
end

#to_sObject



34
35
36
37
# File 'lib/threeuk_usage.rb', line 34

def to_s()
  "Three.co.uk Data Allowance:\n\n\tremaining: %s MB\n\texpires: %s" % \
      [@remaining, @expires]
end