seb 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 50729714cb07e0b3c1ec85a55f4fcf0e4bf84386
4
+ data.tar.gz: 82eea762ff6e69f269fc92032bed6336c954de36
5
+ SHA512:
6
+ metadata.gz: a6dda893f51d82a814e9c55a1bcc360c729b1667264e1a19a9c55f8928bd8985faf95855bba77119a542a196c518cb48eebf260d4a9ae7c7dee9ee510cf42303
7
+ data.tar.gz: 83720a00459f44819a1f2a273c3c7423640cb8e8a9f21fe1ffb523f68e5fb215c2f079faf5c5adbc3559b90f2e7a77411bcb468aa4451d7c0face1ac5cd5c1af
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Yu Wang
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,56 @@
1
+ # Seb
2
+
3
+ It extracts data from exported xlsx file of SEB bank statments and generates a financial report.
4
+
5
+ ## Installation
6
+
7
+ $ gem install seb
8
+
9
+ ## Usage
10
+
11
+ Login to SEB private bank, go to "Mina konton", click "Kontohändelser" and download the exported the .xlsx file.
12
+ Click "Exportera till kalkylblad (xls)" to export:
13
+
14
+ ![SEB screen shot](https://api0-ams1.monosnap.com/static/IutKg0hszJuCy6SF9pqneLYrP0pHAD.png)
15
+
16
+ Then run:
17
+
18
+ $ seb report Export.xlsx
19
+ +---------+-------------------------+
20
+ | Summary |
21
+ +---------+-------------------------+
22
+ | Name | Rex |
23
+ | Account | 12345678 |
24
+ | Dates | 2014-04-14 ~ 2014-08-14 |
25
+ | Balance | 1000.0 |
26
+ | Expense | 500.0 |
27
+ | Income | 1100.0 |
28
+ +---------+-------------------------+
29
+ +---------+---------+--------+---------+
30
+ | Group by Month |
31
+ +---------+---------+--------+---------+
32
+ | Month | Expense | Income | Balance |
33
+ +---------+---------+--------+---------+
34
+ | 2014-08 | 200.0 | 1000.0 | 800.0 |
35
+ | 2014-07 | 100.0 | 0.0 | -100.0 |
36
+ | 2014-06 | 100.0 | 0.0 | -100.0 |
37
+ | 2014-05 | 100.0 | 0.0 | -100.0 |
38
+ | 2014-04 | 0.0 | 100.0 | 100.0 |
39
+ +---------+---------+--------+---------+
40
+
41
+ For help:
42
+
43
+ $ seb help
44
+ Commands:
45
+ seb help [COMMAND] # Describe available commands or one specific command
46
+ seb report FILE # Show the report of the xlsx file
47
+ seb summary FILE # Show the summary of the xlsx file
48
+ seb version # Show version
49
+
50
+ ## Contributing
51
+
52
+ 1. Fork it ( https://github.com/[my-github-username]/seb/fork )
53
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
54
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
55
+ 4. Push to the branch (`git push origin my-new-feature`)
56
+ 5. Create a new Pull Request
@@ -0,0 +1,14 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ t.pattern = "test/*_test.rb"
7
+ end
8
+
9
+ desc "Start the development console"
10
+ task :console do
11
+ require 'pry'
12
+ require 'seb'
13
+ pry
14
+ end
data/bin/seb ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'seb'
4
+ require 'seb/cli'
5
+
6
+ Seb::Cli::App.start ARGV
@@ -0,0 +1,5 @@
1
+ require 'seb/version'
2
+ require 'seb/document'
3
+
4
+ module Seb
5
+ end
@@ -0,0 +1,67 @@
1
+ require 'thor'
2
+ require 'terminal-table'
3
+
4
+ module Seb
5
+ module Cli
6
+ class App < Thor
7
+
8
+ desc 'report FILE', 'Show the report of the xlsx file'
9
+ def report(file)
10
+ report = Report.new file
11
+ puts report.summary
12
+ puts report.group_by_month
13
+ end
14
+
15
+ desc 'summary FILE', 'Show the summary of the xlsx file'
16
+ def summary(file)
17
+ puts Report.new(file).summary
18
+ end
19
+
20
+ desc 'version', 'Show version'
21
+ def version
22
+ puts "seb v#{VERSION}"
23
+ end
24
+
25
+ end
26
+
27
+ class Report
28
+ attr_reader :doc
29
+
30
+ def initialize(file)
31
+ @doc = Document.new file
32
+ end
33
+
34
+ def summary
35
+ dates = doc.transactions.map(&:date)
36
+
37
+ Terminal::Table.new do |t|
38
+ t.title = 'Summary'
39
+ t << ['Name', doc.name]
40
+ t << ['Account', doc.account]
41
+ t << ['Dates', "#{dates.min} ~ #{dates.max}"]
42
+ t << ['Balance', doc.balance]
43
+ t << ['Expense', doc.total[:expense]]
44
+ t << ['Income', doc.total[:income]]
45
+ end
46
+ end
47
+
48
+ def group_by_month
49
+ rows = doc.total_by_month.map do |r|
50
+ [
51
+ r[:month],
52
+ r[:expense],
53
+ r[:income],
54
+ (r[:income] - r[:expense]).round(2)
55
+ ]
56
+ end
57
+
58
+ Terminal::Table.new({
59
+ title: 'Group by Month',
60
+ headings: [:Month, :Expense, :Income, :Balance],
61
+ rows: rows
62
+ })
63
+ end
64
+ end
65
+ end
66
+
67
+ end
@@ -0,0 +1,69 @@
1
+ require 'roo'
2
+ require 'seb/transaction'
3
+
4
+ module Seb
5
+ class Document
6
+ attr_reader :file, :data, :name, :account, :balance, :transactions
7
+
8
+ def initialize(file)
9
+ @file = file
10
+ @data = Roo::Excelx.new file
11
+ end
12
+
13
+ def name
14
+ @name ||= data.cell 1, 1
15
+ end
16
+
17
+ def account
18
+ @account ||= data.cell 2, 1
19
+ end
20
+
21
+ def balance
22
+ @balance ||= data.cell 2, 2
23
+ end
24
+
25
+ def transactions
26
+ @transactions ||= parse_transactions
27
+ end
28
+
29
+ def total
30
+ @total ||= { income: total_income, expense: total_expense }
31
+ end
32
+
33
+ def total_by_month(date_range=nil)
34
+ if date_range.nil?
35
+ transactions
36
+ else
37
+ transactions.select{ |t| date_range.cover? t.date }
38
+ end.group_by do |t|
39
+ t.date.strftime '%Y-%m'
40
+ end.map do |month, data|
41
+ {
42
+ month: month,
43
+ income: total_income(data).round(2),
44
+ expense: total_expense(data).round(2)
45
+ }
46
+ end
47
+ end
48
+
49
+ def to_s
50
+ "<Seb::Document name=#{name} account=#{account} balance=#{balance}>"
51
+ end
52
+
53
+ private
54
+
55
+ def total_income(transactions=transactions)
56
+ transactions.select(&:income?).map(&:amount).sum
57
+ end
58
+
59
+ def total_expense(transactions=transactions)
60
+ transactions.select(&:expense?).map(&:amount).sum * -1
61
+ end
62
+
63
+ def parse_transactions
64
+ first_row = 6
65
+ last_row = data.last_row
66
+ (first_row..last_row).map {|i| Transaction.new data.row(i) }
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,18 @@
1
+ module Seb
2
+ class Transaction
3
+ attr_reader :date, :id, :message, :amount, :balance
4
+
5
+ def initialize(data)
6
+ @date = Date.parse data.first
7
+ _, _, @id, @message, @amount, @balance = data
8
+ end
9
+
10
+ def income?
11
+ amount > 0
12
+ end
13
+
14
+ def expense?
15
+ amount < 0
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ module Seb
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'seb/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'seb'
8
+ spec.version = Seb::VERSION
9
+ spec.authors = ['Yu Wang']
10
+ spec.email = ['wangyuhere@gmail.com']
11
+ spec.summary = %q{Extract data from SEB .xlsx file and generate financial report}
12
+ spec.description = %q{It extracts data from exported .xlsx file of SEB bank statements and generates a financial report.}
13
+ spec.homepage = 'https://github.com/wangyuhere/seb'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split("\n")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_runtime_dependency 'roo'
22
+ spec.add_runtime_dependency 'thor'
23
+ spec.add_runtime_dependency 'terminal-table'
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.6'
26
+ spec.add_development_dependency 'rake'
27
+ spec.add_development_dependency 'minitest'
28
+ spec.add_development_dependency 'pry'
29
+ end
@@ -0,0 +1,41 @@
1
+ require 'minitest/autorun'
2
+ require 'seb'
3
+
4
+ class DocumentTest < Minitest::Test
5
+ SAMPLE_FILE = File.join File.dirname(__FILE__), 'sample.xlsx'
6
+
7
+ def setup
8
+ @doc = Seb::Document.new SAMPLE_FILE
9
+ end
10
+
11
+ def test_parse
12
+ assert_equal 'Rex', @doc.name
13
+ assert_equal '12345678', @doc.account
14
+ assert_equal 1000.0, @doc.balance
15
+ assert_equal 7, @doc.transactions.size
16
+ end
17
+
18
+ def test_total
19
+ total = {income: 1100.0, expense: 500.0}
20
+ assert_equal total, @doc.total
21
+ end
22
+
23
+ def test_total_by_month
24
+ data = @doc.total_by_month
25
+ first_data = {month: '2014-08', income: 1000.0, expense: 200.0}
26
+ last_data = {month: '2014-04', income: 100.0, expense: 0.0}
27
+
28
+ assert_equal 5, data.size
29
+ assert_equal first_data, data.first
30
+ assert_equal last_data, data.last
31
+ end
32
+
33
+ def test_total_by_month_with_range
34
+ data = @doc.total_by_month Date.parse('2014-07-01')..Date.parse('2014-08-31')
35
+ last_data = {month: '2014-07', income: 0.0, expense: 100.0}
36
+
37
+ assert_equal 2, data.size
38
+ assert_equal last_data, data.last
39
+ end
40
+
41
+ end
Binary file
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: seb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Yu Wang
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: roo
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: terminal-table
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.6'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.6'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: It extracts data from exported .xlsx file of SEB bank statements and
112
+ generates a financial report.
113
+ email:
114
+ - wangyuhere@gmail.com
115
+ executables:
116
+ - seb
117
+ extensions: []
118
+ extra_rdoc_files: []
119
+ files:
120
+ - ".gitignore"
121
+ - Gemfile
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - bin/seb
126
+ - lib/seb.rb
127
+ - lib/seb/cli.rb
128
+ - lib/seb/document.rb
129
+ - lib/seb/transaction.rb
130
+ - lib/seb/version.rb
131
+ - seb.gemspec
132
+ - test/document_test.rb
133
+ - test/sample.xlsx
134
+ homepage: https://github.com/wangyuhere/seb
135
+ licenses:
136
+ - MIT
137
+ metadata: {}
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubyforge_project:
154
+ rubygems_version: 2.2.2
155
+ signing_key:
156
+ specification_version: 4
157
+ summary: Extract data from SEB .xlsx file and generate financial report
158
+ test_files:
159
+ - test/document_test.rb
160
+ - test/sample.xlsx