libledger 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a389bd843cbd1fe00130adbd228914fc2be6e8bc
4
- data.tar.gz: 7736b6c5b3d80730f46f3e852cbdada4312691db
3
+ metadata.gz: 88e563136240529f727ae98f888e3b81caa4720b
4
+ data.tar.gz: 3a4eae174f0515427d6fdc3197357b964198e3c2
5
5
  SHA512:
6
- metadata.gz: 5017dbc9256136b0af509801457a91d8156865ecfd1743c1b6e75b7392e4be630afb6c62e6248db4d7bdc5d7591959fe1417f1e4b87e8e6f8aafcabdbf098fce
7
- data.tar.gz: 1c14be5f9762e5d5c7fbb526ae2e900684f864a07110cd93da30f02c2338037cc9cfce848952e6fd15d94a5a3143a3b299f3442505fcba87ce47164ca2a29445
6
+ metadata.gz: f8f994d6113d6c16d605cfa1047d646cd839bdcaafcb1bb9f4d3fbff5d315d1a738fbcbb98e665a2ae9b0984bf44a2c281df24c049df51417e5af134bb498690
7
+ data.tar.gz: 6d95d946a03703961735f0363ca6d41b689bf8c8c9a23cfd59b217b46e2c4dc196d2a29317608d3edb606a1f0a1b941a2fca338e84e0a440c4aa84292bb79e7a
data/.circle-ruby ADDED
@@ -0,0 +1,4 @@
1
+ 2.4.0
2
+ 2.3.3
3
+ 2.2.6
4
+ 2.1.10
data/README.md CHANGED
@@ -3,15 +3,45 @@ libledger
3
3
 
4
4
  [![Gem Version](https://img.shields.io/gem/v/libledger.svg)](https://rubygems.org/gems/libledger)
5
5
  [![Dependency Status](https://img.shields.io/gemnasium/akerl/libledger.svg)](https://gemnasium.com/akerl/libledger)
6
- [![Build Status](https://img.shields.io/circleci/project/akerl/libledger.svg)](https://circleci.com/gh/akerl/libledger)
6
+ [![Build Status](https://img.shields.io/circleci/project/akerl/libledger/master.svg)](https://circleci.com/gh/akerl/libledger)
7
7
  [![Coverage Status](https://img.shields.io/codecov/c/github/akerl/libledger.svg)](https://codecov.io/github/akerl/libledger)
8
- [![Code Quality](https://img.shields.io/codacy/.svg)](https://www.codacy.com/app/akerl/libledger)
8
+ [![Code Quality](https://img.shields.io/codacy/e5360f4242b64246b2a70022616c9bea.svg)](https://www.codacy.com/app/akerl/libledger)
9
9
  [![MIT Licensed](https://img.shields.io/badge/license-MIT-green.svg)](https://tldrlegal.com/license/mit-license)
10
10
 
11
11
  Library for interacting with [Ledger](http://www.ledger-cli.org/) files.
12
12
 
13
13
  ## Usage
14
14
 
15
+ libledger provides Ledger::Entry, which is a transaction, and Ledger::Journal, a list of transactions.
16
+
17
+ To create a new entry:
18
+
19
+ ```
20
+ require 'libledger'
21
+ require 'date'
22
+
23
+ entry = Ledger::Entry.new(
24
+ name: 'Delicious Chipotle Burrito',
25
+ state: :cleared,
26
+ date: Date.today,
27
+ actions: [
28
+ { name: 'Expenses:Burritos', amount: '$6.89' },
29
+ { name: 'Assets:visa' }
30
+ ]
31
+ )
32
+
33
+ # This will print the entry in ledger format
34
+ puts entry
35
+ ```
36
+
37
+ To read an entry, call `Ledger::Entry.from_lines(lines)`. `lines` should be an array of strings, which are the lines of a ledger journal for that transaction.
38
+
39
+ To read a full journal, use `Ledger::Journal.from_file(file)`, where file should be a path to the journal file. If you have multiple files, `Ledger::Journal.from_files(files)` accepts an array of paths.
40
+
41
+ To create a journal, use `Ledger::Journal.new(entries: array_of_entries)`.
42
+
43
+ The output of `.to_s` on a Journal (which is called if you do `puts my_journal` is the ledger text file format for its transactions.
44
+
15
45
  ## Installation
16
46
 
17
47
  gem install libledger
data/circle.yml CHANGED
@@ -1,12 +1,7 @@
1
1
  dependencies:
2
2
  override:
3
- - 'rvm-exec 1.9.3-p551 bundle install'
4
- - 'rvm-exec 2.0.0-p645 bundle install'
5
- - 'rvm-exec 2.1.6 bundle install'
6
- - 'rvm-exec 2.2.2 bundle install'
3
+ - 'for i in $(cat .circle-ruby) ; do rvm-exec $i gem update --system --no-doc || exit 1 ; done'
4
+ - 'for i in $(cat .circle-ruby) ; do rvm-exec $i bundle install || exit 1 ; done'
7
5
  test:
8
6
  override:
9
- - 'rvm-exec 1.9.3-p551 bundle exec rake'
10
- - 'rvm-exec 2.0.0-p645 bundle exec rake'
11
- - 'rvm-exec 2.1.6 bundle exec rake'
12
- - 'rvm-exec 2.2.2 bundle exec rake'
7
+ - 'for i in $(cat .circle-ruby) ; do rvm-exec $i bundle exec rake || exit 1 ; done'
@@ -4,6 +4,11 @@ module Ledger
4
4
  ENTRY_SUBJECT_LINE_REGEX = %r{^(\d+/\d+/\d+) (?:([*!]) )?(.*)$}
5
5
  ENTRY_ACTION_LINE_REGEX = /^\s+(\w+[^( )\t]*)(?:\s+(.*))?$/
6
6
 
7
+ STATE_MAPPING = {
8
+ cleared: '*',
9
+ pending: '!'
10
+ }.freeze
11
+
7
12
  ##
8
13
  # Declaration for entry object
9
14
  class Entry
@@ -19,16 +24,12 @@ module Ledger
19
24
  @state ||= @data[:state]
20
25
  end
21
26
 
22
- def state_as_symbol
23
- return @state_as_symbol if @state_as_symbol
24
- @state = case state
25
- when '*'
26
- :cleared
27
- when '!'
28
- :pending
29
- else
30
- raise "Unexpected state on #{name}: #{state}"
31
- end
27
+ def state_sym
28
+ @state_sym ||= state.is_a?(Symbol) ? state : STATE_MAPPING.invert[state]
29
+ end
30
+
31
+ def state_str
32
+ @state_str ||= state.is_a?(Symbol) ? STATE_MAPPING[state] : state
32
33
  end
33
34
 
34
35
  def date
@@ -48,7 +49,7 @@ module Ledger
48
49
  private
49
50
 
50
51
  def subject_line
51
- "#{date.strftime('%Y/%m/%d')} #{state} #{name}\n"
52
+ "#{date.strftime('%Y/%m/%d')} #{state_str} #{name}\n"
52
53
  end
53
54
 
54
55
  def action_lines
data/libledger.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'libledger'
3
- s.version = '0.0.1'
3
+ s.version = '0.0.2'
4
4
  s.date = Time.now.strftime('%Y-%m-%d')
5
5
 
6
6
  s.summary = 'Library for interacting with Ledger files'
@@ -13,9 +13,9 @@ Gem::Specification.new do |s|
13
13
  s.files = `git ls-files`.split
14
14
  s.test_files = `git ls-files spec/*`.split
15
15
 
16
- s.add_development_dependency 'rubocop', '~> 0.39.0'
17
- s.add_development_dependency 'rake', '~> 11.1.0'
16
+ s.add_development_dependency 'rubocop', '~> 0.47.0'
17
+ s.add_development_dependency 'rake', '~> 12.0.0'
18
18
  s.add_development_dependency 'codecov', '~> 0.1.1'
19
- s.add_development_dependency 'rspec', '~> 3.4.0'
20
- s.add_development_dependency 'fuubar', '~> 2.0.0'
19
+ s.add_development_dependency 'rspec', '~> 3.5.0'
20
+ s.add_development_dependency 'fuubar', '~> 2.2.0'
21
21
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libledger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Les Aker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-25 00:00:00.000000000 Z
11
+ date: 2017-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.39.0
19
+ version: 0.47.0
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.39.0
26
+ version: 0.47.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 11.1.0
33
+ version: 12.0.0
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 11.1.0
40
+ version: 12.0.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: codecov
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -58,34 +58,35 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 3.4.0
61
+ version: 3.5.0
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 3.4.0
68
+ version: 3.5.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: fuubar
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 2.0.0
75
+ version: 2.2.0
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 2.0.0
82
+ version: 2.2.0
83
83
  description: Library for interacting with Ledger files
84
84
  email: me@lesaker.org
85
85
  executables: []
86
86
  extensions: []
87
87
  extra_rdoc_files: []
88
88
  files:
89
+ - ".circle-ruby"
89
90
  - ".gitignore"
90
91
  - ".prospectus"
91
92
  - ".rspec"
@@ -121,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
122
  version: '0'
122
123
  requirements: []
123
124
  rubyforge_project:
124
- rubygems_version: 2.5.1
125
+ rubygems_version: 2.6.8
125
126
  signing_key:
126
127
  specification_version: 4
127
128
  summary: Library for interacting with Ledger files