ofx_reader 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fb5c91a8308601dd54e47ad85d692f312e85aa09
4
+ data.tar.gz: a5df28de0b2884d6b36890e9799cf86e0668ab8c
5
+ SHA512:
6
+ metadata.gz: 438d5f462835849481429ce9e74406e5809b6cddc0cb9796fada9f133e4b95d57cadc0511dc2b42558e6fd82d6b33ce4816afef417e491ab74e0af6b5ad5e178
7
+ data.tar.gz: 04e9ea4d069e328eb6e5f424ebb519ed9f3f25ca64508e507a469aaae8c5b3d20ece688141112c636951638cd53e638076c5c8d6019587d17237def04a0ff3b0
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.0
5
+ before_install: gem install bundler -v 1.16.0
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in ofx_reader.gemspec
6
+ gemspec
7
+
8
+ gem 'simplecov', '~> 0.15', require: false
data/Gemfile.lock ADDED
@@ -0,0 +1,53 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ofx_reader (0.1.0)
5
+ nokogiri (~> 1.8)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ coderay (1.1.2)
11
+ diff-lcs (1.3)
12
+ docile (1.1.5)
13
+ json (2.1.0)
14
+ method_source (0.9.0)
15
+ mini_portile2 (2.3.0)
16
+ nokogiri (1.8.1)
17
+ mini_portile2 (~> 2.3.0)
18
+ pry (0.11.3)
19
+ coderay (~> 1.1.0)
20
+ method_source (~> 0.9.0)
21
+ rake (10.5.0)
22
+ rspec (3.7.0)
23
+ rspec-core (~> 3.7.0)
24
+ rspec-expectations (~> 3.7.0)
25
+ rspec-mocks (~> 3.7.0)
26
+ rspec-core (3.7.0)
27
+ rspec-support (~> 3.7.0)
28
+ rspec-expectations (3.7.0)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.7.0)
31
+ rspec-mocks (3.7.0)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.7.0)
34
+ rspec-support (3.7.0)
35
+ simplecov (0.15.1)
36
+ docile (~> 1.1.0)
37
+ json (>= 1.8, < 3)
38
+ simplecov-html (~> 0.10.0)
39
+ simplecov-html (0.10.2)
40
+
41
+ PLATFORMS
42
+ ruby
43
+
44
+ DEPENDENCIES
45
+ bundler (~> 1.16)
46
+ ofx_reader!
47
+ pry (~> 0.11)
48
+ rake (~> 10.0)
49
+ rspec (~> 3.0)
50
+ simplecov (~> 0.15)
51
+
52
+ BUNDLED WITH
53
+ 1.16.0
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # OfxReader
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ofx_reader`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'ofx_reader'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install ofx_reader
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Credits
34
+
35
+ This gem is based on [ofx](https://github.com/fnando/ofx).
36
+
37
+ ## Contributing
38
+
39
+ Bug reports and pull requests are welcome on GitHub at https://github.com/franciscomxs/ofx_reader.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ofx_reader"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,40 @@
1
+ module OFXReader
2
+ module Parser
3
+ class Base
4
+ require 'nokogiri'
5
+ require 'time'
6
+
7
+ attr_reader :headers, :body, :content
8
+
9
+ def initialize(content)
10
+ @content = content.encode("UTF-8", "ISO-8859-1")
11
+ @headers, @body = read(@content)
12
+ end
13
+
14
+ private
15
+
16
+ def read(content)
17
+ headers, body = content.dup.split(/(?=<OFX>)/, 2)
18
+ headers = parse_headers(headers)
19
+ body = parse_body(body)
20
+ [headers, body]
21
+ end
22
+
23
+ def parse_headers(headers)
24
+ headers.each_line.with_object({}) do |line, hash|
25
+ _, k, v = *line.match(/^(.*?):(.*?)\s*(\r?\n)*$/)
26
+ hash[k] = v unless v.nil?
27
+ end
28
+ end
29
+
30
+ def parse_body(body)
31
+ # body.prepend('<OFX>')
32
+ body.gsub!(/>\s+</m, '><')
33
+ body.gsub!(/\s+</m, '<')
34
+ body.gsub!(/>\s+/m, '>')
35
+ body.gsub!(/<(\w+?)>([^<]+)/m, '<\1>\2</\1>')
36
+ body = ::Nokogiri::XML(body)
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,46 @@
1
+ module OFXReader
2
+ module Parser
3
+ class OFX102 < OFXReader::Parser::Base
4
+
5
+ ACCOUNT_TYPES = [
6
+ "CHECKING",
7
+ "SAVINGS",
8
+ "CREDITCARD",
9
+ "CREDITLINE",
10
+ "INVESTMENT",
11
+ "MONEYMRKT",
12
+ ]
13
+
14
+ TRANSACTION_TYPES = [
15
+ 'ATM', 'CASH', 'CHECK', 'CREDIT', 'DEBIT', 'DEP', 'DIRECTDEBIT',
16
+ 'DIRECTDEP', 'DIV', 'FEE', 'INT', 'OTHER', 'PAYMENT', 'POS',
17
+ 'REPEATPMT', 'SRVCHG', 'XFER',
18
+ ].inject({}) { |hash, type| hash.tap { |h| h[type] = type.downcase } }
19
+
20
+ def account
21
+ {
22
+ bank_id: body.search('BANKACCTFROM BANKID').inner_text,
23
+ account_id: body.search('BANKACCTFROM ACCTID').inner_text,
24
+ }
25
+ end
26
+
27
+ def transactions
28
+ body.search('BANKTRANLIST STMTTRN').map do |node|
29
+ build_transaction(node)
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def build_transaction(node)
36
+ {
37
+ type: node.search('TRNTYPE').text,
38
+ time: Time.parse(node.search('DTPOSTED').text),
39
+ amount: node.search('TRNAMT').text.to_f,
40
+ fit_id: node.search('FITID').text,
41
+ name: node.search('NAME').text
42
+ }
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,3 @@
1
+ module OFXReader
2
+ VERSION = "0.1.0"
3
+ end
data/lib/ofx_reader.rb ADDED
@@ -0,0 +1,13 @@
1
+ require "ofx_reader/version"
2
+
3
+ begin
4
+ require "pry"
5
+ rescue LoadError
6
+ end
7
+
8
+ require "ofx_reader/parser/base"
9
+ require "ofx_reader/parser/ofx_102"
10
+
11
+ module OFXReader
12
+ # Your code goes here...
13
+ end
@@ -0,0 +1,26 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "ofx_reader/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "ofx_reader"
7
+ spec.version = OFXReader::VERSION
8
+ spec.authors = ["Francisco Martins"]
9
+ spec.email = ["franciscomxs@gmail.com"]
10
+
11
+ spec.summary = "A simple ofx reader"
12
+ spec.homepage = "https://github.com/franciscomxs/ofx_reader"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
15
+ f.match(%r{^(test|spec|features)/})
16
+ end
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "nokogiri", "~> 1.8"
22
+ spec.add_development_dependency "bundler", "~> 1.16"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+ spec.add_development_dependency "pry", "~> 0.11"
26
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ofx_reader
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Francisco Martins
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-12-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.11'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.11'
83
+ description:
84
+ email:
85
+ - franciscomxs@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - Gemfile.lock
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - lib/ofx_reader.rb
100
+ - lib/ofx_reader/parser/base.rb
101
+ - lib/ofx_reader/parser/ofx_102.rb
102
+ - lib/ofx_reader/version.rb
103
+ - ofx_reader.gemspec
104
+ homepage: https://github.com/franciscomxs/ofx_reader
105
+ licenses: []
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.6.13
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: A simple ofx reader
127
+ test_files: []