journala 0.1.0

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.
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "activesupport"
4
+
5
+ group :development do
6
+ gem 'jeweler'
7
+ gem 'rcov'
8
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,21 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (3.1.0)
5
+ multi_json (~> 1.0)
6
+ git (1.2.5)
7
+ jeweler (1.6.4)
8
+ bundler (~> 1.0)
9
+ git (>= 1.2.5)
10
+ rake
11
+ multi_json (1.0.3)
12
+ rake (0.9.2.2)
13
+ rcov (0.9.11)
14
+
15
+ PLATFORMS
16
+ ruby
17
+
18
+ DEPENDENCIES
19
+ activesupport
20
+ jeweler
21
+ rcov
data/README.txt ADDED
@@ -0,0 +1,5 @@
1
+ Booker
2
+
3
+ Inspired by Ledger. It reads and creates the same format as Ledger.
4
+
5
+ Also included is a class to parse Amazon/Chase credit card data.
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "journala"
18
+ gem.homepage = "http://github.com/kirkland/journala"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{inspired by ledger}
21
+ gem.description = %Q{a library that reads and write ledger format ledger files}
22
+ gem.email = "rob.m.kaufman@gmail.com"
23
+ gem.authors = ["Robert Kaufman"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ require 'rcov/rcovtask'
36
+ Rcov::RcovTask.new do |test|
37
+ test.libs << 'test'
38
+ test.pattern = 'test/**/test_*.rb'
39
+ test.verbose = true
40
+ test.rcov_opts << '--exclude "gems/*"'
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "journala #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/journala.gemspec ADDED
@@ -0,0 +1,54 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "journala"
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Robert Kaufman"]
12
+ s.date = "2011-11-25"
13
+ s.description = "a library that reads and write ledger format ledger files"
14
+ s.email = "rob.m.kaufman@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "README.txt"
17
+ ]
18
+ s.files = [
19
+ "Gemfile",
20
+ "Gemfile.lock",
21
+ "README.txt",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "journala.gemspec",
25
+ "lib/journala.rb",
26
+ "lib/journala/entry.rb",
27
+ "lib/journala/journal.rb",
28
+ "lib/journala/row.rb"
29
+ ]
30
+ s.homepage = "http://github.com/kirkland/journala"
31
+ s.licenses = ["MIT"]
32
+ s.require_paths = ["lib"]
33
+ s.rubygems_version = "1.8.10"
34
+ s.summary = "inspired by ledger"
35
+
36
+ if s.respond_to? :specification_version then
37
+ s.specification_version = 3
38
+
39
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
40
+ s.add_runtime_dependency(%q<activesupport>, [">= 0"])
41
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
42
+ s.add_development_dependency(%q<rcov>, [">= 0"])
43
+ else
44
+ s.add_dependency(%q<activesupport>, [">= 0"])
45
+ s.add_dependency(%q<jeweler>, [">= 0"])
46
+ s.add_dependency(%q<rcov>, [">= 0"])
47
+ end
48
+ else
49
+ s.add_dependency(%q<activesupport>, [">= 0"])
50
+ s.add_dependency(%q<jeweler>, [">= 0"])
51
+ s.add_dependency(%q<rcov>, [">= 0"])
52
+ end
53
+ end
54
+
@@ -0,0 +1,21 @@
1
+ module Journala
2
+ class Entry
3
+ attr_accessor :date, :description, :confirmed, :rows
4
+
5
+ def initialize(attrs={})
6
+ @rows = []
7
+ attrs.each do |k,v|
8
+ self.send("#{k}=", v)
9
+ end
10
+ end
11
+
12
+ def <<(new_row)
13
+ @rows << new_row
14
+ end
15
+
16
+ def to_s
17
+ confirmed_str = @confirmed? " *" : ""
18
+ %{#{@date}#{confirmed_str} #{@description}\n#{@rows.collect(&:to_s).join("\n")}}
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,96 @@
1
+ module Journala
2
+ class Journal
3
+ attr_accessor :entries
4
+
5
+ def initialize
6
+ @entries = []
7
+ end
8
+
9
+ def print
10
+ sort_by_date
11
+
12
+ @entries.each do |x|
13
+ puts x
14
+ puts "\n"
15
+ end
16
+ nil
17
+ end
18
+
19
+ def sort_by_date
20
+ @entries = @entries.sort do |a,b|
21
+ a.date <=> b.date
22
+ end
23
+ end
24
+
25
+ def write_to_file(filename, overwrite=false)
26
+ if File.exist?(filename) && !overwrite
27
+ raise "File #{filename} already exists. Set second parameter to true to overwrite anyway"
28
+ end
29
+
30
+ sort_by_date
31
+
32
+ f = File.open(filename, 'w')
33
+
34
+ @entries.each do |e|
35
+ f.puts(e)
36
+ f.puts "\n"
37
+ end
38
+
39
+ f.close
40
+ end
41
+
42
+ # merge journal with another journal. when an identical transaction is found,
43
+ # keep our own entry, and discard other_journal's entry.
44
+ # the idea is that we read in an existing journal from a file, and then add
45
+ # new entries only to it
46
+ def merge(other_journal)
47
+ puts "before merge: #{@entries.count} entries"
48
+ other_journal.entries.each do |entry|
49
+ transaction_id = entry.description.match(/\(transaction id: (\d+)\)/)[1]
50
+
51
+ if @entries.none? {|e| e.description.match(/\(transaction id: \d+\)/) }
52
+ @entries << entry
53
+ end
54
+ end
55
+ puts "after merge: #{@entries.count} entries"
56
+ end
57
+
58
+ class << self
59
+ def create_from_file(filename)
60
+ file = File.open(filename, 'r')
61
+
62
+ journal = Journal.new
63
+
64
+ file.each_line do |line|
65
+ if line =~ /^$/
66
+ next
67
+ elsif line =~ /^(\d\d\d\d\/\d\d\/\d\d)\s*(\*)*\s*(.*)/
68
+ date = $1
69
+ confirmed = $2
70
+ description = $3
71
+
72
+ entry = Entry.new(:date => date, :confirmed => confirmed.present?, :description => description)
73
+
74
+ journal.entries << entry
75
+
76
+ # row with amount
77
+ elsif line =~ /\s+(.*)\s{2,}\$(.*)/
78
+ row = Row.new(:account => $1, :amount => $2)
79
+ journal.entries.last.rows << row
80
+
81
+ # row without amount
82
+ elsif line =~ /\s+(.*)/
83
+ other_amount = journal.entries.last.rows.first.amount
84
+ row = Row.new(:account => $1, :amount => 0-other_amount)
85
+ journal.entries.last.rows << row
86
+ end
87
+
88
+ end
89
+
90
+ f.close
91
+
92
+ journal
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,25 @@
1
+ module Journala
2
+ class Row
3
+ attr_accessor :account
4
+ attr_reader :amount
5
+
6
+ def initialize(attrs={})
7
+ attrs.each do |k,v|
8
+ self.send("#{k}=", v)
9
+ end
10
+ end
11
+
12
+ def amount=(incoming_amount)
13
+ @amount = Value.new(incoming_amount.to_s)
14
+ end
15
+
16
+ def valid?
17
+ @account.present? && @amount.present?
18
+ end
19
+
20
+ def to_s
21
+ spaces = ' ' * (70 - @account.length - @amount.length)
22
+ " #{@account}#{spaces}#{@amount}"
23
+ end
24
+ end
25
+ end
data/lib/journala.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'bigdecimal'
2
+ require 'active_support/all'
3
+ require 'journala/journal'
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: journala
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Robert Kaufman
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-11-25 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: &70306852090220 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70306852090220
25
+ - !ruby/object:Gem::Dependency
26
+ name: jeweler
27
+ requirement: &70306852089740 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70306852089740
36
+ - !ruby/object:Gem::Dependency
37
+ name: rcov
38
+ requirement: &70306852089260 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70306852089260
47
+ description: a library that reads and write ledger format ledger files
48
+ email: rob.m.kaufman@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files:
52
+ - README.txt
53
+ files:
54
+ - Gemfile
55
+ - Gemfile.lock
56
+ - README.txt
57
+ - Rakefile
58
+ - VERSION
59
+ - journala.gemspec
60
+ - lib/journala.rb
61
+ - lib/journala/entry.rb
62
+ - lib/journala/journal.rb
63
+ - lib/journala/row.rb
64
+ homepage: http://github.com/kirkland/journala
65
+ licenses:
66
+ - MIT
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ segments:
78
+ - 0
79
+ hash: 2348405985660087486
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project:
88
+ rubygems_version: 1.8.10
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: inspired by ledger
92
+ test_files: []