transactions 0.1.0 → 0.1.1
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 +4 -4
- data/CHANGELOG.md +10 -6
- data/README.md +8 -6
- data/bin/transactions +1 -1
- data/lib/transactions.rb +0 -2
- data/lib/transactions/main.rb +10 -0
- data/lib/transactions/options.rb +7 -0
- data/lib/transactions/parser.rb +28 -27
- data/lib/transactions/version.rb +1 -1
- data/test/ledger.yaml +58 -0
- data/test/test_transactions.rb +36 -0
- data/transactions.gemspec +28 -0
- metadata +13 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33eda3b0328f7e73b955157f5e6546a02318dd39
|
4
|
+
data.tar.gz: b5517d7c6f82f774478fed0b3201233221836ac4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e48557d6ce160b64d8222d6697aa2a431c3ff38aa5f867e96020b05d042d978852f5108eb3b9a9097227a4a61e4cace27caf57db60dec9b9dfe06bd1814d6a90
|
7
|
+
data.tar.gz: 862a28891b7a1a138714d0ca2a391718f19286ee9744c29ec8927395fe7187e10409980bb9630a3aca82ec576e765fb11c606c114971f88248caa202bcdb5204
|
data/CHANGELOG.md
CHANGED
@@ -1,11 +1,15 @@
|
|
1
|
+
## version 0.1.1 (2013-06-28)
|
2
|
+
* refactored transaction parser
|
3
|
+
* added some tomdocs to code
|
4
|
+
* included test directory in gem pkg
|
5
|
+
|
6
|
+
|
1
7
|
## version 0.1.0 (2013-06-27)
|
2
|
-
|
3
|
-
*
|
4
|
-
*
|
5
|
-
* Authored README.md
|
8
|
+
* initial Release
|
9
|
+
* added additional unit tests
|
10
|
+
* authored README.md
|
6
11
|
|
7
12
|
|
8
13
|
## version 0.0.0 (2013-06-26)
|
9
|
-
|
10
|
-
* Happy Birthday!
|
14
|
+
* happy birthday!
|
11
15
|
|
data/README.md
CHANGED
@@ -21,7 +21,7 @@ on your system. Note that RubyGems is included with Ruby since version 1.9.
|
|
21
21
|
The best way to install transactions is via RubyGems. At the terminal prompt, run
|
22
22
|
the following command:
|
23
23
|
|
24
|
-
|
24
|
+
gem install transactions
|
25
25
|
|
26
26
|
|
27
27
|
## Additional Information
|
@@ -227,14 +227,16 @@ Limit by date
|
|
227
227
|
How to get your work merged into the project?
|
228
228
|
|
229
229
|
* Fork the project.
|
230
|
-
* Clone your fork ( git clone git@github.com:<username>/transactions.git ).
|
231
|
-
* Create a topic branch for your change ( git checkout -b my_new_feature ).
|
230
|
+
* Clone your fork ( `git clone git@github.com:<username>/transactions.git` ).
|
231
|
+
* Create a topic branch for your change ( `git checkout -b my_new_feature` ).
|
232
232
|
* Hack away, add tests. Not necessarily in that order.
|
233
|
-
* Make sure everything still passes by running
|
233
|
+
* Make sure everything still passes by running `ruby test_transactions.rb`
|
234
|
+
from within the test directory (tests need to be run in the same directory
|
235
|
+
as the included **ledger.yaml** file).
|
234
236
|
* If necessary, rebase your commits into logical chunks, without errors.
|
235
|
-
* Push the branch up ( git push origin my_new_feature ).
|
237
|
+
* Push the branch up ( `git push origin my_new_feature` ).
|
236
238
|
* Create a pull request against randyschneck/transactions and describe what
|
237
|
-
your change does and
|
239
|
+
your change does and/or why you think it should be merged.
|
238
240
|
|
239
241
|
|
240
242
|
## Credits
|
data/bin/transactions
CHANGED
data/lib/transactions.rb
CHANGED
data/lib/transactions/main.rb
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
module Transaction
|
2
2
|
|
3
|
+
# Public: Initializes a Transaction::Parser object. A 'ledger.yaml' file must
|
4
|
+
# exist in the current working directory.
|
5
|
+
#
|
6
|
+
# Examples
|
7
|
+
#
|
8
|
+
# require 'transactions'
|
9
|
+
# # read the ledger.yaml file into a Transaction::Parser object
|
10
|
+
# t = Transaction::Parser.new
|
11
|
+
#
|
12
|
+
# Returns nothing
|
3
13
|
class Parser
|
4
14
|
|
5
15
|
def initialize
|
data/lib/transactions/options.rb
CHANGED
@@ -6,6 +6,9 @@ module Transaction
|
|
6
6
|
@options = {}
|
7
7
|
end
|
8
8
|
|
9
|
+
# Internal: Parses options for transactions from the command line.
|
10
|
+
#
|
11
|
+
# Returns nothing.
|
9
12
|
def options
|
10
13
|
OptionParser.new do |opts|
|
11
14
|
|
@@ -68,6 +71,10 @@ module Transaction
|
|
68
71
|
end
|
69
72
|
|
70
73
|
|
74
|
+
# Internal: Prints help for commands that are stored in ARGV[0]. Used in
|
75
|
+
# help menu.
|
76
|
+
#
|
77
|
+
# Returns nothing.
|
71
78
|
def commands_help
|
72
79
|
<<-COMMANDHELP
|
73
80
|
|
data/lib/transactions/parser.rb
CHANGED
@@ -1,5 +1,25 @@
|
|
1
1
|
module Transaction
|
2
2
|
|
3
|
+
# Public: This is the actual parser for generating financial reports.
|
4
|
+
#
|
5
|
+
# cmd - A String for the command to run through parser. Must be 'balance',
|
6
|
+
# 'register', or 'print'.
|
7
|
+
#
|
8
|
+
# Examples
|
9
|
+
#
|
10
|
+
# require 'transactions'
|
11
|
+
# t = Transaction::Parser.new
|
12
|
+
# ARGV[0] == "" # The function requires ARGV[0] even if it's empty
|
13
|
+
# t.parse 'balance'
|
14
|
+
# t.parse 'register'
|
15
|
+
# t.parse 'print'
|
16
|
+
# ARGV[1] = 'checking'
|
17
|
+
# t.parse 'register'
|
18
|
+
# ARGV[1] = 'income'
|
19
|
+
# ARGV[2] = 'expenses'
|
20
|
+
# t.parse 'balance'
|
21
|
+
#
|
22
|
+
# Returns Hash containing accounts and totals if cmd is 'balance'
|
3
23
|
def parse(cmd)
|
4
24
|
|
5
25
|
@accounts = {}
|
@@ -19,38 +39,19 @@ module Transaction
|
|
19
39
|
|
20
40
|
def transaction_register(x, k, v, running_total)
|
21
41
|
if v.is_a? Numeric
|
22
|
-
if @options[:wide]
|
23
|
-
|
24
|
-
|
25
|
-
k[0..42], v, running_total)
|
26
|
-
else # for printing 78 columns wide (default)
|
27
|
-
t = "%10s %-20s %-24s %10.2f %10.2f"
|
28
|
-
puts sprintf(t, x['date'], x['transaction'][0..18],
|
29
|
-
k[0..22], v, running_total)
|
30
|
-
end
|
42
|
+
t = "%10s %-44.42s %-44.42s %15.2f %15.2f" if @options[:wide]
|
43
|
+
t = "%10s %-20.18s %-24.22s %10.2f %10.2f" unless @options[:wide]
|
44
|
+
puts sprintf(t, x['date'], x['transaction'], k, v, running_total)
|
31
45
|
end
|
32
46
|
end
|
33
47
|
|
34
48
|
def transaction_command(cmd, x, k, v)
|
35
49
|
ARGV.map! { |z| z.downcase }
|
36
|
-
if ARGV[1..-1].any? { |arg| k.downcase.include? arg }
|
37
|
-
@running_total += v if v.is_a? Numeric
|
38
|
-
if cmd == 'print'
|
39
|
-
transaction_print(x)
|
40
|
-
elsif cmd == 'balance'
|
41
|
-
transaction_balance(k, v)
|
42
|
-
elsif cmd == 'register'
|
43
|
-
transaction_register(x, k, v, @running_total)
|
44
|
-
end
|
45
|
-
elsif !ARGV[1]
|
50
|
+
if ARGV[1..-1].any? { |arg| k.downcase.include? arg } || !ARGV[1]
|
46
51
|
@running_total += v if v.is_a? Numeric
|
47
|
-
if cmd == 'print'
|
48
|
-
|
49
|
-
|
50
|
-
transaction_balance(k, v)
|
51
|
-
elsif cmd == 'register'
|
52
|
-
transaction_register(x, k, v, @running_total)
|
53
|
-
end
|
52
|
+
transaction_print(x) if cmd == 'print'
|
53
|
+
transaction_balance(k, v) if cmd == 'balance'
|
54
|
+
transaction_register(x, k, v, @running_total) if cmd == 'register'
|
54
55
|
end
|
55
56
|
end
|
56
57
|
|
@@ -154,9 +155,9 @@ module Transaction
|
|
154
155
|
end
|
155
156
|
end
|
156
157
|
end
|
158
|
+
@accounts
|
157
159
|
end
|
158
160
|
|
159
|
-
|
160
161
|
end
|
161
162
|
end
|
162
163
|
|
data/lib/transactions/version.rb
CHANGED
data/test/ledger.yaml
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# This is a sample ledger file
|
2
|
+
# this line and the one above are comments that will be ignored
|
3
|
+
# during processing! Comments can also be placed at the end of
|
4
|
+
# a line (see below for examples).
|
5
|
+
|
6
|
+
- date: 2013/01/01
|
7
|
+
transaction: Opening Balances
|
8
|
+
Assets:Checking: 251.0
|
9
|
+
Assets:Savings: 5005.3
|
10
|
+
Assets:IRA: 22510.92
|
11
|
+
Liabilities:CreditCard: -931.32
|
12
|
+
Liabilities:Salliemae: -10189.05
|
13
|
+
Equity:OpeningBalances: -16646.85
|
14
|
+
|
15
|
+
- date: 2013/01/07
|
16
|
+
transaction: Trader Joe's
|
17
|
+
Expenses:Food:Groceries: 58.77
|
18
|
+
Assets:Checking: -58.77
|
19
|
+
|
20
|
+
- date: 2013/01/09
|
21
|
+
transaction: Student Loan Payment
|
22
|
+
Liabilities:Salliemae: 103.3
|
23
|
+
Expenses:Interest:StudentLoan: 15.04
|
24
|
+
Assets:Checking: -118.34
|
25
|
+
|
26
|
+
- date: 2013/02/11
|
27
|
+
transaction: Deposit Paycheck
|
28
|
+
Assets:Checking: 1242.87
|
29
|
+
Income:JobName: -1242.87
|
30
|
+
|
31
|
+
- date: 2013/02/11
|
32
|
+
transaction: Visa Payment
|
33
|
+
Expenses:Interest:CreditCard: 10.0
|
34
|
+
Liabilities:CreditCard: 130.0
|
35
|
+
Assets:Checking: -140.0
|
36
|
+
|
37
|
+
- date: 2013/02/25
|
38
|
+
transaction: PG&E
|
39
|
+
Expenses:Utilities:Electric: 75
|
40
|
+
Assets:Checking: -75
|
41
|
+
|
42
|
+
- date: 2013/02/25
|
43
|
+
transaction: Verizon # Switch to Virgin Mobile
|
44
|
+
Expenses:Phone: 55.72
|
45
|
+
Assets:Checking: -55.72
|
46
|
+
|
47
|
+
- date: 2013/02/26
|
48
|
+
transaction: Ike's Lair # good sandwich
|
49
|
+
Expenses:Food:Dining: 22.31
|
50
|
+
Assets:Checking: -22.31
|
51
|
+
|
52
|
+
# a transaction requires only one space as a separator but can also be
|
53
|
+
# aligned as above. The choice is yours!
|
54
|
+
|
55
|
+
- date: 2013/02/26
|
56
|
+
transaction: Money Transfer
|
57
|
+
Assets:Savings: 494.7
|
58
|
+
Assets:Checking: -494.7
|
@@ -0,0 +1,36 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), *%w{ .. lib })
|
2
|
+
|
3
|
+
require "test/unit"
|
4
|
+
require "../lib/transactions"
|
5
|
+
|
6
|
+
class TestTransactions < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def test_options # make sure options are initiated
|
9
|
+
test_options = Transaction::Options.new.options
|
10
|
+
assert_equal(test_options, {})
|
11
|
+
test_options[:file] = 'test'
|
12
|
+
assert_equal(test_options, {:file=>'test'})
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_balances # make sure accounts balance in test "ledger.yaml"
|
16
|
+
ARGV[0] = ""
|
17
|
+
accounts = Transaction::Parser.new.parse("balance")
|
18
|
+
accounts.each do |x|
|
19
|
+
assert_equal(529.03, x[1].round(2)) if x[0] == "Assets:Checking"
|
20
|
+
assert_equal(22510.92, x[1].round(2)) if x[0] == "Assets:IRA"
|
21
|
+
assert_equal(5500.00, x[1].round(2)) if x[0] == "Assets:Savings"
|
22
|
+
assert_equal(-16646.85, x[1].round(2)) if x[0] == "Equity:OpeningBalances"
|
23
|
+
assert_equal(22.31, x[1].round(2)) if x[0] == "Expenses:Food:Dining"
|
24
|
+
assert_equal(58.77, x[1].round(2)) if x[0] == "Expenses:Food:Groceries"
|
25
|
+
assert_equal(10.00, x[1].round(2)) if x[0] == "Expenses:Interest:CreditCard"
|
26
|
+
assert_equal(15.04, x[1].round(2)) if x[0] == "Expenses:Interest:StudentLoan"
|
27
|
+
assert_equal(55.72, x[1].round(2)) if x[0] == "Expenses:Phone"
|
28
|
+
assert_equal(75.00, x[1].round(2)) if x[0] == "Expenses:Utilities:Electric"
|
29
|
+
assert_equal(-1242.87, x[1].round(2)) if x[0] == "Income:JobName"
|
30
|
+
assert_equal(-801.32, x[1].round(2)) if x[0] == "Liabilities:CreditCard"
|
31
|
+
assert_equal(-10085.75, x[1].round(2)) if x[0] == "Liabilities:Salliemae"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
lib = File.expand_path('../lib/', __FILE__)
|
2
|
+
$:.unshift lib unless $:.include?(lib)
|
3
|
+
|
4
|
+
require 'transactions/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = 'transactions'
|
8
|
+
s.version = Transaction::VERSION
|
9
|
+
|
10
|
+
s.summary = "A bookkeeping application to help manage your finances."
|
11
|
+
s.description = <<-EOF
|
12
|
+
A small but powerful command line application to help manage finances.
|
13
|
+
Transactions are entered into a text file using yaml and reports are
|
14
|
+
generated by parsing this data.
|
15
|
+
EOF
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_path = 'lib'
|
21
|
+
s.require_paths = %w[lib]
|
22
|
+
s.executables = ["transactions"]
|
23
|
+
|
24
|
+
s.authors = ["Randy Schneck"]
|
25
|
+
s.email = 'rasch@computercrayons.com'
|
26
|
+
s.homepage = 'https://github.com/randyschneck/transactions'
|
27
|
+
s.license = 'MIT'
|
28
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: transactions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Randy Schneck
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-06-
|
11
|
+
date: 2013-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |2
|
14
14
|
A small but powerful command line application to help manage finances.
|
@@ -20,15 +20,18 @@ executables:
|
|
20
20
|
extensions: []
|
21
21
|
extra_rdoc_files: []
|
22
22
|
files:
|
23
|
+
- CHANGELOG.md
|
24
|
+
- LICENSE.md
|
25
|
+
- README.md
|
23
26
|
- bin/transactions
|
27
|
+
- lib/transactions.rb
|
24
28
|
- lib/transactions/main.rb
|
25
29
|
- lib/transactions/options.rb
|
26
30
|
- lib/transactions/parser.rb
|
27
31
|
- lib/transactions/version.rb
|
28
|
-
-
|
29
|
-
-
|
30
|
-
-
|
31
|
-
- CHANGELOG.md
|
32
|
+
- test/ledger.yaml
|
33
|
+
- test/test_transactions.rb
|
34
|
+
- transactions.gemspec
|
32
35
|
homepage: https://github.com/randyschneck/transactions
|
33
36
|
licenses:
|
34
37
|
- MIT
|
@@ -49,8 +52,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
49
52
|
version: '0'
|
50
53
|
requirements: []
|
51
54
|
rubyforge_project:
|
52
|
-
rubygems_version: 2.0.
|
55
|
+
rubygems_version: 2.0.3
|
53
56
|
signing_key:
|
54
57
|
specification_version: 4
|
55
58
|
summary: A bookkeeping application to help manage your finances.
|
56
|
-
test_files:
|
59
|
+
test_files:
|
60
|
+
- test/ledger.yaml
|
61
|
+
- test/test_transactions.rb
|