libledger 0.0.5 → 0.0.6

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
  SHA256:
3
- metadata.gz: d4c1251e5757f71ce2f5fb4da604bdb84e5143f572c192efad37aef61025cb53
4
- data.tar.gz: 1498456ce69ab6b1ffc39976fca6f606e13ba5b018614715a9aec0bcb4d86cda
3
+ metadata.gz: c8d479856702cc84e796c55b0d2aaeda59e8ccd7cf3fe57a755ab1e7c0ffc9a1
4
+ data.tar.gz: 006c5b66fcb248f3dbbaa31a4f11794ed34dcfdc758bb49f3e4a619a7aad82d9
5
5
  SHA512:
6
- metadata.gz: 4a64125c2bc312f41f24eea920c911245585b37f10de409f680806eebedde2cb56cac04b579f76f4414deb26a2490fe2c5c1ca3e32272f252e66a98ef4f9fdbc
7
- data.tar.gz: 8b67c9737ad5bb04697cc8084261cf956bc1a43c69a1be08f3e8d538c4be1f26cdc84ffce970eb52515f68cee7dd1224f64aa8fae78dfe955c82255882b53f45
6
+ metadata.gz: 863d70a6641aa1fe0f0e443b138aa536a09c553d4b842ea8df0ec2ea2c5b22dc20e917fed19e40fae9c1be5409ba6ef36be1762a811857efff5324013aa0a5ea
7
+ data.tar.gz: 0d0fff90cbc369a2118eb08ac7d9375ca40adae91ffd1ec8e2b23829c60b8502698aa0a5905d5a02609e3026955c4e9d4a7e2678f20a921a0ad359d5c2e18a5b
data/.circle-ruby CHANGED
@@ -1,3 +1,4 @@
1
+ 2.6.1
1
2
  2.5.3
2
3
  2.4.5
3
4
  2.3.8
data/.travis.yml CHANGED
@@ -1,4 +1,4 @@
1
- dist: trusty
1
+ dist: xenial
2
2
  install:
3
3
  - for i in $(cat .circle-ruby) ; do rvm install $i || exit 1 ; done
4
4
  - for i in $(cat .circle-ruby) ; do rvm-exec $i bundle install || exit 1 ; done
@@ -1,8 +1,9 @@
1
1
  require 'date'
2
2
 
3
3
  module Ledger
4
- ENTRY_SUBJECT_LINE_REGEX = %r{^(\d+/\d+/\d+) (?:([*!]) )?(.*)$}
5
- ENTRY_ACTION_LINE_REGEX = /^\s+(\w+[^( )\t]*)(?:\s+(.*))?$/
4
+ ENTRY_SUBJECT_LINE_REGEX = %r{^(\d+/\d+/\d+) (?:([*!]) )?(.*)$}.freeze
5
+ ENTRY_ACTION_LINE_REGEX = /^\s+(\w+[^( )\t]*)(?:\s+(.*))?$/.freeze
6
+ ENTRY_TAG_LINE_REGEX = /^\s+; (\w+): (.*)$/.freeze
6
7
 
7
8
  STATE_MAPPING = {
8
9
  cleared: '*',
@@ -44,8 +45,12 @@ module Ledger
44
45
  @actions ||= @data[:actions]
45
46
  end
46
47
 
48
+ def tags
49
+ @tags ||= @data[:tags] || {}
50
+ end
51
+
47
52
  def to_s
48
- subject_line + action_lines.join("\n") + "\n"
53
+ subject_line + tag_lines + action_lines.join("\n") + "\n"
49
54
  end
50
55
 
51
56
  def <=>(other)
@@ -59,6 +64,12 @@ module Ledger
59
64
  "#{date.strftime('%Y/%m/%d')} #{state_str} #{name}\n"
60
65
  end
61
66
 
67
+ def tag_lines
68
+ res = tags.map { |k, v| " ; #{k}: #{v}" }.join("\n")
69
+ res += "\n" unless res.empty?
70
+ res
71
+ end
72
+
62
73
  def action_lines
63
74
  actions.map do |x|
64
75
  line = " #{x[:name]}"
@@ -75,12 +86,22 @@ module Ledger
75
86
  class << self
76
87
  def from_lines(lines)
77
88
  params = parse_first_line(lines.shift)
78
- params[:actions] = lines.map { |x| parse_action_line x }
89
+ params[:tags] = {}
90
+ params[:actions] = lines.map do |x|
91
+ m = x.match(ENTRY_TAG_LINE_REGEX)
92
+ next(parse_action_line(x)) unless m
93
+ params[:tags][m[1]] = m[2]
94
+ nil
95
+ end.compact
79
96
  Entry.new(params)
80
97
  end
81
98
 
82
99
  private
83
100
 
101
+ def parse_tag_line(line)
102
+ line.match(ENTRY_TAG_LINE_REGEX).captures
103
+ end
104
+
84
105
  def parse_first_line(line)
85
106
  date, state, name = line.match(ENTRY_SUBJECT_LINE_REGEX).captures
86
107
  {
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.5'
3
+ s.version = '0.0.6'
4
4
  s.date = Time.now.strftime('%Y-%m-%d')
5
5
 
6
6
  s.summary = 'Library for interacting with Ledger files'
@@ -15,8 +15,8 @@ Gem::Specification.new do |s|
15
15
 
16
16
  s.add_development_dependency 'codecov', '~> 0.1.1'
17
17
  s.add_development_dependency 'fuubar', '~> 2.3.0'
18
- s.add_development_dependency 'goodcop', '~> 0.6.0'
18
+ s.add_development_dependency 'goodcop', '~> 0.7.0'
19
19
  s.add_development_dependency 'rake', '~> 12.3.0'
20
20
  s.add_development_dependency 'rspec', '~> 3.8.0'
21
- s.add_development_dependency 'rubocop', '~> 0.59.0'
21
+ s.add_development_dependency 'rubocop', '~> 0.67.2'
22
22
  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.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Les Aker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-20 00:00:00.000000000 Z
11
+ date: 2019-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: codecov
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.6.0
47
+ version: 0.7.0
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.6.0
54
+ version: 0.7.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 0.59.0
89
+ version: 0.67.2
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 0.59.0
96
+ version: 0.67.2
97
97
  description: Library for interacting with Ledger files
98
98
  email: me@lesaker.org
99
99
  executables: []
@@ -135,8 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
135
  - !ruby/object:Gem::Version
136
136
  version: '0'
137
137
  requirements: []
138
- rubyforge_project:
139
- rubygems_version: 2.7.6
138
+ rubygems_version: 3.0.1
140
139
  signing_key:
141
140
  specification_version: 4
142
141
  summary: Library for interacting with Ledger files