ofx_ruby 0.0.13 → 0.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c64f0acb70d7928cdf68a2a56f927f16930797e3
4
- data.tar.gz: 9589928dfcaf5df283504eabd5d5a2b6112030ee
3
+ metadata.gz: b41ef0ed969fef00bb94b4685bc08edf1c1f301b
4
+ data.tar.gz: bfbe06e5523d12018f521bd39e9053a18dd35074
5
5
  SHA512:
6
- metadata.gz: 2056a66be490fadf0072ec12117c563fabf9c13984ae5d46b580ffe5c292870d7697b640c0a3ff4bb54068a1446fb7731d8532467f5ee202c2dfdf236ea71004
7
- data.tar.gz: 7d0108b6805f314665e78bddc5284fc759ce82f291088f3bd8ba787002665792d7b1b01031521bcc4b17f847e2ec4020535b1a3f2787e958c0afed5dd34ad231
6
+ metadata.gz: d2eef49cd742e94af56db6e2e4e1437609fed4d8933cad65e0e6f7ab0732a584a03e8de1dff1669589c8da293c5b0c6e32cdf593d92a529a42f580d4a8c97d3f
7
+ data.tar.gz: f17dc8ad3b4f30cb9ae0f29e2f324abffe0647b4b73bc3c3e18b2c652e66b3124f38859a1fd6db20167fe99caf2e0b597a7cc5ba51203d3d3c59e3a52a2efae2
data/lib/ofx/handler.rb CHANGED
@@ -2,7 +2,8 @@
2
2
  module OFX
3
3
  class Handler < Ox::Sax
4
4
  TRANSACTION_ATTRS = [:TRNTYPE, :DTPOSTED, :TRNAMT, :FITID, :NAME]
5
- ATTRS_MAP = { TRNTYPE: :as_s, DTPOSTED: :as_time,
5
+ BALANCE_ATTRS = [:BALAMT]
6
+ ATTRS_MAP = { TRNTYPE: :as_s, DTPOSTED: :as_time, BALAMT: :as_f,
6
7
  TRNAMT: :as_f, FITID: :as_s, NAME: :as_s }
7
8
 
8
9
  def initialize(parser)
@@ -10,25 +11,40 @@ module OFX
10
11
  end
11
12
 
12
13
  def start_element(name)
13
- @transaction = {} if name == :STMTTRN
14
- @current_node = name
14
+ case name
15
+ when :STMTTRN then @transaction = {}
16
+ when :LEDGERBAL || :AVAILBAL then @balance = {}
17
+ end
18
+ @current = name
15
19
  end
16
20
 
17
21
  def value(value)
18
- return unless TRANSACTION_ATTRS.include?(@current_node)
19
- @transaction[@current_node] = value.send(ATTRS_MAP[@current_node])
22
+ case
23
+ when TRANSACTION_ATTRS.include?(@current)
24
+ @transaction[@current] = value.send(ATTRS_MAP[@current])
25
+ when BALANCE_ATTRS.include?(@current)
26
+ @balance[@current] = value.send(ATTRS_MAP[@current])
27
+ end
20
28
  end
21
29
 
22
30
  def end_element(name)
23
- return unless name == :STMTTRN
24
- @parser.output[:transactions] = [] if @parser.output[:transactions].nil?
25
- @parser.output[:transactions].push(
26
- type: @transaction[:TRNTYPE],
27
- posted: @transaction[:DTPOSTED],
28
- amount: @transaction[:TRNAMT],
29
- fitid: @transaction[:FITID],
30
- name: @transaction[:NAME]
31
- )
31
+ case name
32
+ when :STMTTRN
33
+ @parser.output[:transactions] = [] unless @parser.output[:transactions]
34
+ @parser.output[:transactions].push(transaction(@transaction))
35
+ when :LEDGERBAL
36
+ @parser.output[:balance] = @balance[:BALAMT]
37
+ when :AVAILBAL
38
+ @parser.output[:pending] = @balance[:BALAMT] - @parser.output[:balance]
39
+ end
40
+ end
41
+
42
+ protected
43
+
44
+ def transaction(hash)
45
+ { type: @transaction[:TRNTYPE], posted: @transaction[:DTPOSTED],
46
+ amount: @transaction[:TRNAMT], fitid: @transaction[:FITID],
47
+ name: @transaction[:NAME] }
32
48
  end
33
49
  end
34
50
  end
data/lib/ofx/parser.rb CHANGED
@@ -18,6 +18,14 @@ module OFX
18
18
  @output[:transactions]
19
19
  end
20
20
 
21
+ def balance
22
+ @output[:balance].round(2)
23
+ end
24
+
25
+ def pending
26
+ @output[:pending].round(2)
27
+ end
28
+
21
29
  protected
22
30
 
23
31
  def dump
data/lib/ofx/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module OFX
2
- VERSION = "0.0.13"
2
+ VERSION = "0.0.14"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ofx_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - rob
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-29 00:00:00.000000000 Z
11
+ date: 2016-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler