Class: CommerceBank
Instance Attribute Summary collapse
-
#available ⇒ Object
readonly
Returns the value of attribute available.
-
#current ⇒ Object
readonly
Returns the value of attribute current.
-
#register ⇒ Object
readonly
Returns the value of attribute register.
Instance Method Summary collapse
- #daily_summary {|'Pending', @pending| ... } ⇒ Object
-
#initialize ⇒ CommerceBank
constructor
A new instance of CommerceBank.
- #monthly_summary(day_in_month = (Date.today - Date.today.day)) {|day_in_month.strftime('%B'), entries| ... } ⇒ Object
Constructor Details
#initialize ⇒ CommerceBank
Returns a new instance of CommerceBank.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/commercebank.rb', line 71 def initialize @config = AppConfig.new('~/.commerce.yaml') client = WebClient.new client.get('/') client.get('/CBI/login.aspx', 'MAINFORM') client.fields['txtUserID'] = @config[:username] response = client.post('/CBI/login.aspx', 'MAINFORM') # If a question was asked, answer it then get the password page. question = response.body.scan(/Your security question: (.*?)<\/td>/i).first.andand.first if question client.fields['txtChallengeAnswer'] = @config[question] client.fields['saveComputer'] = 'rdoBindDeviceNo' response = client.post('/CBI/login.aspx', 'MAINFORM') end raise "could not reach the password page" unless client.fields['__EVENTTARGET'] == 'btnLogin' client.fields['txtPassword'] = @config[:password] response = client.post('/CBI/login.aspx') response = client.get('/CBI/Accounts/CBI/Activity.aspx', 'MAINFORM') (@current, @available) = parse_balance(response.body) @pending = parse_pending(response.body) client.fields['Anthem_UpdatePage'] = 'true' client.fields['txtFilterFromDate:textBox'] = Time.parse('1/1/2000').strftime('%m/%d/%Y') client.fields['txtFilterToDate:textBox'] = Time.now.strftime('%m/%d/%Y') response = client.post('/CBI/Accounts/CBI/Activity.aspx?Anthem_CallBack=true') raw_data = JSON.parse(response.body) @register = parse_register(raw_data['controls']['pnlPosted']) end |
Instance Attribute Details
#available ⇒ Object (readonly)
Returns the value of attribute available.
69 70 71 |
# File 'lib/commercebank.rb', line 69 def available @available end |
#current ⇒ Object (readonly)
Returns the value of attribute current.
69 70 71 |
# File 'lib/commercebank.rb', line 69 def current @current end |
#register ⇒ Object (readonly)
Returns the value of attribute register.
69 70 71 |
# File 'lib/commercebank.rb', line 69 def register @register end |
Instance Method Details
#daily_summary {|'Pending', @pending| ... } ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/commercebank.rb', line 109 def daily_summary today, yesterday, this_week, last_week = [], [], [], [] register.each do |entry| if entry[:date] == Date.today then today << entry elsif entry[:date] == (Date.today - 1) then yesterday << entry elsif entry[:date] >= Date.today.last_sunday then this_week << entry elsif entry[:date] >= (Date.today.last_sunday - 1).last_sunday then last_week << entry end end yield 'Pending', @pending yield 'Today', today yield 'Yesterday', yesterday yield 'This Week', this_week yield 'Last Week', last_week end |
#monthly_summary(day_in_month = (Date.today - Date.today.day)) {|day_in_month.strftime('%B'), entries| ... } ⇒ Object
127 128 129 130 131 132 133 134 |
# File 'lib/commercebank.rb', line 127 def monthly_summary(day_in_month = (Date.today - Date.today.day)) first_of_month = day_in_month - day_in_month.day + 1 last_of_month = first_of_month + day_in_month.days_in_month - 1 entries = register.find_all {|entry| entry[:date] >= first_of_month && entry[:date] <= last_of_month} yield day_in_month.strftime('%B'), entries end |