Class: Journala::Parsers::Chase
- Inherits:
-
Object
- Object
- Journala::Parsers::Chase
- Defined in:
- lib/journala/parsers/chase.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
for debugging.
-
#doc ⇒ Object
for debugging.
-
#journal ⇒ Object
for debugging.
-
#json ⇒ Object
for debugging.
Class Method Summary collapse
Instance Attribute Details
#data ⇒ Object
for debugging. in normal usage you only need @journal, which is returned anyway
9 10 11 |
# File 'lib/journala/parsers/chase.rb', line 9 def data @data end |
#doc ⇒ Object
for debugging. in normal usage you only need @journal, which is returned anyway
9 10 11 |
# File 'lib/journala/parsers/chase.rb', line 9 def doc @doc end |
#journal ⇒ Object
for debugging. in normal usage you only need @journal, which is returned anyway
9 10 11 |
# File 'lib/journala/parsers/chase.rb', line 9 def journal @journal end |
#json ⇒ Object
for debugging. in normal usage you only need @journal, which is returned anyway
9 10 11 |
# File 'lib/journala/parsers/chase.rb', line 9 def json @json end |
Class Method Details
.parse(input_filename = "Account Activity.html") ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/journala/parsers/chase.rb', line 11 def self.parse(input_filename="Account Activity.html") @doc = open(input_filename) {|f| Hpricot(f) } # data is contained inside a script tag script = @doc.search("#chaseui-pagecontent").search("script")[0].inner_html @data = script.match(/activity = ({.*})/)[1] @json = JSON.parse(@data) @journal = Journal.new @json['Posted'].each do |raw_entry| entry = Entry.new m,d,y = raw_entry['tranDate'].split('/') entry.date = %{#{y}/#{m.rjust(2, '0')}/#{d.rjust(2, '0')}} m,d,y = raw_entry['postDate'].split('/') posted_date = %{#{y}/#{m.rjust(2, '0')}/#{d.rjust(2, '0')}} amount = raw_entry['amount'].gsub(/\$/, '') merchant = raw_entry['merchantName'] trans_type = raw_entry['tranType'] trans_id = raw_entry['tranId'] entry.description = "#{merchant} (posted #{posted_date}) (transaction id: #{trans_id})" r1 = Row.new r1.account = 'Liabilities:Amazon/Chase CC' r1.amount = 0 - amount.to_f entry.rows << r1 r2 = Row.new r2.account = trans_type == 'Payment' ? 'Assets:Current Assets:Central Bank' : 'Expenses:Uncategorized' r2.amount = 0 - r1.amount entry.rows << r2 if !['Sale', 'Return', 'Payment'].include?(trans_type) raise "oh no found type: #{entry.type} ! what do i do?!" end @journal.entries << entry end @journal end |