Class: Natwest::Customer
Constant Summary collapse
- NO_DETAILS =
'No further transaction details held'
Instance Attribute Summary collapse
-
#page ⇒ Object
Returns the value of attribute page.
Attributes included from Login
#customer_number, #password, #pin, #ua
Instance Method Summary collapse
- #accounts ⇒ Object
-
#initialize ⇒ Customer
constructor
A new instance of Customer.
Methods included from Login
Constructor Details
#initialize ⇒ Customer
Returns a new instance of Customer.
72 73 74 |
# File 'lib/natwest.rb', line 72 def initialize @ua = Mechanize.new {|ua| ua.user_agent_alias = 'Windows IE 7'} end |
Instance Attribute Details
#page ⇒ Object
Returns the value of attribute page.
70 71 72 |
# File 'lib/natwest.rb', line 70 def page @page end |
Instance Method Details
#accounts ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/natwest.rb', line 76 def accounts page.parser.css('table.AccountTable > tbody > tr').each_slice(2).map do |, statement| Account.new.tap do |acc| acc.name = .at('td > span.AccountName').inner_text acc.number = .at('td > span.AccountNumber').inner_text.gsub(/[^\d]/,'') acc.sort_code = .at('td > span.SortCode').inner_text.gsub(/[^\d-]/,'') acc.balance = .css('td')[-2].inner_text acc.available = .css('td')[-1].inner_text acc.transactions = statement.css('table.InnerAccountTable > tbody > tr').map do |tr| transaction = Hash[[:date, :details, :credit, :debit]. zip((cells = tr.css('td')).map(&:inner_text))] unless (further = cells[1]['title']) == NO_DETAILS transaction[:details] += " (#{further.squeeze(' ')})" end Hash[transaction.map{|k,v| [k, v == ' - ' ? nil : v]}] end end end end |