ofx 0.2.8 → 0.2.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ofx (0.2.7)
4
+ ofx (0.2.8)
5
5
  nokogiri
6
6
 
7
7
  GEM
data/lib/ofx.rb CHANGED
@@ -1,6 +1,9 @@
1
1
  require "open-uri"
2
2
  require "nokogiri"
3
3
 
4
+ require "iconv"
5
+ require "kconv"
6
+
4
7
  require "ofx/errors"
5
8
  require "ofx/parser"
6
9
  require "ofx/parser/ofx102"
@@ -1,6 +1,3 @@
1
- require "iconv"
2
- require "kconv"
3
-
4
1
  module OFX
5
2
  module Parser
6
3
  class Base
@@ -42,35 +39,35 @@ module OFX
42
39
  end
43
40
 
44
41
  private
45
- def prepare(content)
46
- # Split headers & body
47
- headers, body = content.dup.split(/<OFX>/, 2)
42
+ def prepare(content)
43
+ # Split headers & body
44
+ headers, body = content.dup.split(/<OFX>/, 2)
48
45
 
49
- # Change single CR's to LF's to avoid issues with some banks
50
- headers.gsub!(/\r(?!\n)/, "\n")
46
+ # Change single CR's to LF's to avoid issues with some banks
47
+ headers.gsub!(/\r(?!\n)/, "\n")
51
48
 
52
- raise OFX::UnsupportedFileError unless body
49
+ raise OFX::UnsupportedFileError unless body
53
50
 
54
- # Parse headers. When value is NONE, convert it to nil.
55
- headers = headers.to_enum(:each_line).inject({}) do |memo, line|
56
- _, key, value = *line.match(/^(.*?):(.*?)(\r?\n)*$/)
57
- memo[key] = value == "NONE" ? nil : value
58
- memo
59
- end
51
+ # Parse headers. When value is NONE, convert it to nil.
52
+ headers = headers.to_enum(:each_line).inject({}) do |memo, line|
53
+ _, key, value = *line.match(/^(.*?):(.*?)(\r?\n)*$/)
54
+ memo[key] = value == "NONE" ? nil : value
55
+ memo
56
+ end
60
57
 
61
- # Replace body tags to parse it with Nokogiri
62
- body.gsub!(/>\s+</m, '><')
63
- body.gsub!(/\s+</m, '<')
64
- body.gsub!(/>\s+/m, '>')
65
- body.gsub!(/<(\w+?)>([^<]+)/m, '<\1>\2</\1>')
58
+ # Replace body tags to parse it with Nokogiri
59
+ body.gsub!(/>\s+</m, '><')
60
+ body.gsub!(/\s+</m, '<')
61
+ body.gsub!(/>\s+/m, '>')
62
+ body.gsub!(/<(\w+?)>([^<]+)/m, '<\1>\2</\1>')
66
63
 
67
- [headers, body]
68
- end
69
-
70
- def convert_to_utf8(string)
71
- return string if Kconv.isutf8(string)
72
- Iconv.conv('UTF-8', 'LATIN1//IGNORE', string)
73
- end
64
+ [headers, body]
65
+ end
66
+
67
+ def convert_to_utf8(string)
68
+ return string if Kconv.isutf8(string)
69
+ Iconv.conv('UTF-8', 'LATIN1//IGNORE', string)
70
+ end
74
71
  end
75
72
  end
76
73
  end
@@ -4,92 +4,93 @@ module OFX
4
4
  module Parser
5
5
  class OFX102
6
6
  VERSION = "1.0.2"
7
-
7
+
8
8
  ACCOUNT_TYPES = {
9
9
  "CHECKING" => :checking
10
10
  }
11
-
11
+
12
12
  TRANSACTION_TYPES = {
13
13
  "CREDIT" => :credit,
14
14
  "DEBIT" => :debit,
15
15
  "OTHER" => :other,
16
16
  "DEP" => :dep,
17
17
  "XFER" => :xfer,
18
- "CASH" => :cash
18
+ "CASH" => :cash,
19
+ "CHECK" => :check
19
20
  }
20
-
21
+
21
22
  attr_reader :headers
22
23
  attr_reader :body
23
24
  attr_reader :html
24
-
25
+
25
26
  def initialize(options = {})
26
27
  @headers = options[:headers]
27
28
  @body = options[:body]
28
29
  @html = Nokogiri::HTML.parse(body)
29
30
  end
30
-
31
+
31
32
  def account
32
33
  @account ||= build_account
33
34
  end
34
-
35
+
35
36
  private
36
- def build_account
37
- OFX::Account.new({
38
- :bank_id => html.search("bankacctfrom > bankid").inner_text,
39
- :id => html.search("bankacctfrom > acctid").inner_text,
40
- :type => ACCOUNT_TYPES[html.search("bankacctfrom > accttype").inner_text],
41
- :transactions => build_transactions,
42
- :balance => build_balance,
43
- :currency => html.search("bankmsgsrsv1 > stmttrnrs > stmtrs > curdef").inner_text
44
- })
45
- end
46
-
47
- def build_transactions
48
- html.search("banktranlist > stmttrn").collect do |element|
49
- build_transaction(element)
50
- end
51
- end
52
-
53
- def build_transaction(element)
54
- OFX::Transaction.new({
55
- :amount => build_amount(element),
56
- :amount_in_pennies => (build_amount(element) * 100).to_i,
57
- :fit_id => element.search("fitid").inner_text,
58
- :memo => element.search("memo").inner_text,
59
- :payee => element.search("payee").inner_text,
60
- :check_number => element.search("checknum").inner_text,
61
- :ref_number => element.search("refnum").inner_text,
62
- :posted_at => build_date(element.search("dtposted").inner_text),
63
- :type => build_type(element)
64
- })
65
- end
37
+ def build_account
38
+ OFX::Account.new({
39
+ :bank_id => html.search("bankacctfrom > bankid").inner_text,
40
+ :id => html.search("bankacctfrom > acctid").inner_text,
41
+ :type => ACCOUNT_TYPES[html.search("bankacctfrom > accttype").inner_text],
42
+ :transactions => build_transactions,
43
+ :balance => build_balance,
44
+ :currency => html.search("bankmsgsrsv1 > stmttrnrs > stmtrs > curdef").inner_text
45
+ })
46
+ end
66
47
 
67
- def build_type(element)
68
- TRANSACTION_TYPES[element.search("trntype").inner_text]
48
+ def build_transactions
49
+ html.search("banktranlist > stmttrn").collect do |element|
50
+ build_transaction(element)
69
51
  end
52
+ end
70
53
 
71
- def build_amount(element)
72
- BigDecimal.new(element.search("trnamt").inner_text)
73
- end
74
-
75
- def build_date(date)
76
- _, year, month, day, hour, minutes, seconds = *date.match(/(\d{4})(\d{2})(\d{2})(?:(\d{2})(\d{2})(\d{2}))?/)
77
-
78
- date = "#{year}-#{month}-#{day} "
79
- date << "#{hour}:#{minutes}:#{seconds}" if hour && minutes && seconds
80
-
81
- Time.parse(date)
82
- end
83
-
84
- def build_balance
85
- amount = html.search("ledgerbal > balamt").inner_text.to_f
86
-
87
- OFX::Balance.new({
88
- :amount => amount,
89
- :amount_in_pennies => (amount * 100).to_i,
90
- :posted_at => build_date(html.search("ledgerbal > dtasof").inner_text)
91
- })
92
- end
54
+ def build_transaction(element)
55
+ OFX::Transaction.new({
56
+ :amount => build_amount(element),
57
+ :amount_in_pennies => (build_amount(element) * 100).to_i,
58
+ :fit_id => element.search("fitid").inner_text,
59
+ :memo => element.search("memo").inner_text,
60
+ :payee => element.search("payee").inner_text,
61
+ :check_number => element.search("checknum").inner_text,
62
+ :ref_number => element.search("refnum").inner_text,
63
+ :posted_at => build_date(element.search("dtposted").inner_text),
64
+ :type => build_type(element)
65
+ })
66
+ end
67
+
68
+ def build_type(element)
69
+ TRANSACTION_TYPES[element.search("trntype").inner_text]
70
+ end
71
+
72
+ def build_amount(element)
73
+ BigDecimal.new(element.search("trnamt").inner_text)
74
+ end
75
+
76
+ def build_date(date)
77
+ _, year, month, day, hour, minutes, seconds = *date.match(/(\d{4})(\d{2})(\d{2})(?:(\d{2})(\d{2})(\d{2}))?/)
78
+
79
+ date = "#{year}-#{month}-#{day} "
80
+ date << "#{hour}:#{minutes}:#{seconds}" if hour && minutes && seconds
81
+
82
+ Time.parse(date)
83
+ end
84
+
85
+ def build_balance
86
+ amount = html.search("ledgerbal > balamt").inner_text.to_f
87
+
88
+ OFX::Balance.new({
89
+ :amount => amount,
90
+ :amount_in_pennies => (amount * 100).to_i,
91
+ :posted_at => build_date(html.search("ledgerbal > dtasof").inner_text)
92
+ })
93
+ end
93
94
  end
94
95
  end
95
96
  end
@@ -2,7 +2,7 @@ module OFX
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 2
5
- PATCH = 8
5
+ PATCH = 9
6
6
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
  end
8
8
  end
@@ -21,8 +21,6 @@ Usage:
21
21
  end
22
22
  TXT
23
23
 
24
- s.rubyforge_project = "ofx"
25
-
26
24
  s.files = `git ls-files`.split("\n")
27
25
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
28
26
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
@@ -40,6 +40,14 @@ NEWFILEUID:NONE
40
40
  <BANKTRANLIST>
41
41
  <DTSTART>20100930
42
42
  <DTEND>20101025
43
+ <STMTTRN>
44
+ <TRNTYPE>CHECK
45
+ <DTPOSTED>20100826
46
+ <TRNAMT>-836.30
47
+ <FITID>20100826183630
48
+ <CHECKNUM>850076
49
+ <MEMO>CHEQUE COMPENSADO
50
+ </STMTTRN>
43
51
  <STMTTRN>
44
52
  <TRNTYPE>DEBIT
45
53
  <DTPOSTED>20101001
@@ -114,20 +114,25 @@ describe OFX::Transaction do
114
114
  end
115
115
 
116
116
  it "should return dep" do
117
- @transaction = @account.transactions[8]
117
+ @transaction = @account.transactions[9]
118
118
  @transaction.type.should == :dep
119
119
  end
120
120
 
121
121
  it "should return xfer" do
122
- @transaction = @account.transactions[17]
122
+ @transaction = @account.transactions[18]
123
123
  @transaction.type.should == :xfer
124
124
  end
125
125
 
126
126
  it "should return cash" do
127
- @transaction = @account.transactions[44]
127
+ @transaction = @account.transactions[45]
128
128
  @transaction.type.should == :cash
129
129
  end
130
130
 
131
+ it "should return check" do
132
+ @transaction = @account.transactions[0]
133
+ @transaction.type.should == :check
134
+ end
135
+
131
136
  end
132
137
 
133
138
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 8
9
- version: 0.2.8
8
+ - 9
9
+ version: 0.2.9
10
10
  platform: ruby
11
11
  authors:
12
12
  - Nando Vieira
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-10-30 00:00:00 -02:00
17
+ date: 2010-11-10 00:00:00 -02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  version: "0"
118
118
  requirements: []
119
119
 
120
- rubyforge_project: ofx
120
+ rubyforge_project:
121
121
  rubygems_version: 1.3.7
122
122
  signing_key:
123
123
  specification_version: 3