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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e28f5b4cd7a280a48db419b0cd1627b15f58f378
4
- data.tar.gz: ff2653e81dd62e11b13445200a245b71d7ce2fa2
3
+ metadata.gz: df187f2848829cd2041ff61c0608e9ef6565cd4d
4
+ data.tar.gz: dfe92f7df442936a4663f23a7f0d86948675756d
5
5
  SHA512:
6
- metadata.gz: 1b772d292612ace47dadc918b8249865a315a0a4ad5f364a9db1b03ae55fa9a67935e83d73fc72a54009e8574c8a53effed372aa0f7534e98bf35b77eb2b7bcb
7
- data.tar.gz: 63401db844403490ae269c271691fa9db8b6405c295546b9518277ebf820d356e6e51bba9d938e7b591536e47aff7e32d97b86cdb71f2f74beb6f0957e7abefc
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
- months = options[:months].to_i || 12
25
- projection = Ballista.new(entries: config).project(months)
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
@@ -9,10 +9,8 @@ module Ballista
9
9
  @entries = params[:entries]
10
10
  end
11
11
 
12
- def project(months)
13
- start = Date.today + 1
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
 
@@ -1,5 +1,5 @@
1
1
  ##
2
2
  # Set the version (needed for Mercenary -v)
3
3
  module Ballista
4
- VERSION = '0.0.2'.freeze
4
+ VERSION = '0.0.3'.freeze
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ballista
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Les Aker