ballista 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/ballista +27 -2
- data/lib/ballista/projection.rb +2 -4
- data/lib/ballista/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df187f2848829cd2041ff61c0608e9ef6565cd4d
|
4
|
+
data.tar.gz: dfe92f7df442936a4663f23a7f0d86948675756d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45e390ce041a275e89491de8455016b4b34804a6682e7f24d75d9f29c6227c32af84246af9a610ee392e5af6746ee28c82a4a8f1989486316f0d8e42b054f538
|
7
|
+
data.tar.gz: c6f2d58b24dcbb3cb8a988f8d89f0b4c9d27e924a01d23bbac3b60fb44996cad8d86a4fb2fa8786108e17de1f67d01072058b215c81a1d153a7c3e2437d2e790
|
data/bin/ballista
CHANGED
@@ -4,11 +4,32 @@ require 'ballista'
|
|
4
4
|
require 'yaml'
|
5
5
|
require 'mercenary'
|
6
6
|
require 'cymbal'
|
7
|
+
require 'date'
|
7
8
|
|
8
9
|
def parse_config(file)
|
9
10
|
Cymbal.symbolize(YAML.load(File.read(file)))
|
10
11
|
end
|
11
12
|
|
13
|
+
def count_months(months)
|
14
|
+
return unless months
|
15
|
+
start_dt = Date.today + 1
|
16
|
+
end_dt = start_dt >> months.to_i
|
17
|
+
[start_dt, end_dt]
|
18
|
+
end
|
19
|
+
|
20
|
+
def parse_start_end(start_dt, end_dt)
|
21
|
+
return unless start_dt || end_dt
|
22
|
+
raise('Must specify start and end together') unless start_dt && end_dt
|
23
|
+
[Date.parse(start_dt), Date.parse(end_dt)]
|
24
|
+
end
|
25
|
+
|
26
|
+
def parse_range(months, start_dt, end_dt)
|
27
|
+
if months && (start_dt || end_dt)
|
28
|
+
raise('Cannot specify months *and* start/end')
|
29
|
+
end
|
30
|
+
count_months(months) || parse_start_end(start_dt, end_dt) || count_months(12)
|
31
|
+
end
|
32
|
+
|
12
33
|
Mercenary.program(:ballista) do |p|
|
13
34
|
p.version Ballista::VERSION
|
14
35
|
p.description 'Tool for projecting future activity with Ledger'
|
@@ -16,13 +37,17 @@ Mercenary.program(:ballista) do |p|
|
|
16
37
|
|
17
38
|
p.option :output, '-o FILE', '--output FILE', 'Output file for ledger'
|
18
39
|
p.option :months, '-m INT', '--months INT', 'How far ahead to project'
|
40
|
+
p.option :start, '-s DATE', '--start DATE', 'When to start the projection'
|
41
|
+
p.option :end, '-e DATE', '--end DATE', 'When to end the projection'
|
19
42
|
|
20
43
|
p.action do |_, options|
|
21
44
|
config_file = ARGV.shift
|
22
45
|
puts p unless config_file
|
23
46
|
config = parse_config(config_file)
|
24
|
-
|
25
|
-
|
47
|
+
|
48
|
+
start_dt, end_dt = parse_range(*options.values_at(:months, :start, :end))
|
49
|
+
|
50
|
+
projection = Ballista.new(entries: config).project(start_dt, end_dt)
|
26
51
|
if options[:output]
|
27
52
|
File.open(options[:output], 'w') { |fh| fh << projection.to_s }
|
28
53
|
else
|
data/lib/ballista/projection.rb
CHANGED
@@ -9,10 +9,8 @@ module Ballista
|
|
9
9
|
@entries = params[:entries]
|
10
10
|
end
|
11
11
|
|
12
|
-
def project(
|
13
|
-
|
14
|
-
finish = start >> months
|
15
|
-
entries = start.upto(finish).map { |date| parse_day(date) }
|
12
|
+
def project(start_dt, end_dt)
|
13
|
+
entries = start_dt.upto(end_dt).map { |date| parse_day(date) }
|
16
14
|
Ledger.new(entries: entries.flatten)
|
17
15
|
end
|
18
16
|
|
data/lib/ballista/version.rb
CHANGED