ballista 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 98d859e7cd342d957cb3a859d1c0dbad9d0e9b3e
4
+ data.tar.gz: ce880f15be9b6b97d1dfb2f0366bd72b941cd45d
5
+ SHA512:
6
+ metadata.gz: c19d72ea5c1387012e4630c8410e076acb5cc7327a0e4121434dec4f42a9d78c1d903f21e67567560edb8fd9a115b2b8012894528bc7df02f278f3f410d9359d
7
+ data.tar.gz: 0f34f5fc4284b40dd31c664787c7baaf773bd27129b4e3c93af9c4287089c7a39ee0f561cef466cba3ef4321711153c945962cc987ed057a858c280c52568079
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ pkg/*.gem
2
+ coverage/
3
+ .coveralls.yml
4
+ .bundle
5
+ Gemfile.lock
data/.prospectus ADDED
@@ -0,0 +1,11 @@
1
+ item do
2
+ expected do
3
+ static
4
+ set 'green'
5
+ end
6
+
7
+ actual do
8
+ gemnasium
9
+ slug 'akerl/ballista'
10
+ end
11
+ end
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format Fuubar
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,2 @@
1
+ Encoding:
2
+ Enabled: false
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Les Aker
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,22 @@
1
+ ballista
2
+ =========
3
+
4
+ [![Gem Version](https://img.shields.io/gem/v/ballista.svg)](https://rubygems.org/gems/ballista)
5
+ [![Dependency Status](https://img.shields.io/gemnasium/akerl/ballista.svg)](https://gemnasium.com/akerl/ballista)
6
+ [![Build Status](https://img.shields.io/circleci/project/akerl/ballista.svg)](https://circleci.com/gh/akerl/ballista)
7
+ [![Coverage Status](https://img.shields.io/codecov/c/github/akerl/ballista.svg)](https://codecov.io/github/akerl/ballista)
8
+ [![Code Quality](https://img.shields.io/codacy/c9caebd934f04ca699d1f02fac6dcf22.svg)](https://www.codacy.com/app/akerl/ballista)
9
+ [![MIT Licensed](https://img.shields.io/badge/license-MIT-green.svg)](https://tldrlegal.com/license/mit-license)
10
+
11
+ Helper for projecting based on [Ledger](http://www.ledger-cli.org/) format.
12
+
13
+ ## Usage
14
+
15
+ ## Installation
16
+
17
+ gem install ballista
18
+
19
+ ## License
20
+
21
+ ballista is released under the MIT License. See the bundled LICENSE file for details.
22
+
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
4
+
5
+ desc 'Run tests'
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ desc 'Run Rubocop on the gem'
9
+ RuboCop::RakeTask.new(:rubocop) do |task|
10
+ task.patterns = ['lib/**/*.rb', 'spec/**/*.rb', 'bin/*']
11
+ task.fail_on_error = true
12
+ end
13
+
14
+ task default: [:spec, :rubocop, :build, :install]
data/ballista.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ $:.unshift File.expand_path('../lib/', __FILE__)
2
+ require 'ballista/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'ballista'
6
+ s.version = Ballista::VERSION
7
+ s.date = Time.now.strftime('%Y-%m-%d')
8
+
9
+ s.summary = 'Projection tool for Ledger format'
10
+ s.description = "Projection tool for Ledger format"
11
+ s.authors = ['Les Aker']
12
+ s.email = 'me@lesaker.org'
13
+ s.homepage = 'https://github.com/akerl/ballista'
14
+ s.license = 'MIT'
15
+
16
+ s.files = `git ls-files`.split
17
+ s.test_files = `git ls-files spec/*`.split
18
+ s.executables = ['ballista']
19
+
20
+ s.add_dependency 'libledger', '~> 0.0.1'
21
+ s.add_dependency 'mercenary', '~> 0.3.4'
22
+ s.add_dependency 'cymbal', '~> 1.0.0'
23
+
24
+ s.add_development_dependency 'rubocop', '~> 0.39.0'
25
+ s.add_development_dependency 'rake', '~> 11.1.0'
26
+ s.add_development_dependency 'codecov', '~> 0.1.1'
27
+ s.add_development_dependency 'rspec', '~> 3.4.0'
28
+ s.add_development_dependency 'fuubar', '~> 2.0.0'
29
+ end
data/bin/ballista ADDED
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'ballista'
4
+ require 'yaml'
5
+ require 'mercenary'
6
+ require 'cymbal'
7
+
8
+ def parse_config(file)
9
+ Cymbal.symbolize(YAML.load(File.read(file)))
10
+ end
11
+
12
+ Mercenary.program(:ballista) do |p|
13
+ p.version Ballista::VERSION
14
+ p.description 'Tool for projecting future activity with Ledger'
15
+ p.syntax 'ballista [options] CONFIG_FILE'
16
+
17
+ p.option :output, '-o FILE', '--output FILE', 'Output file for ledger'
18
+ p.option :months, '-m INT', '--months INT', 'How far ahead to project'
19
+
20
+ p.action do |_, options|
21
+ config_file = ARGV.shift
22
+ puts p unless config_file
23
+ config = parse_config(config_file)
24
+ months = options[:months] || 12
25
+ projection = Ballista.new(entries: config).project(months)
26
+ if options[:output]
27
+ File.open(options[:output], 'w') { |fh| fh << projection.to_s }
28
+ else
29
+ puts projection
30
+ end
31
+ end
32
+ end
data/circle.yml ADDED
@@ -0,0 +1,12 @@
1
+ dependencies:
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'
7
+ test:
8
+ 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'
data/lib/ballista.rb ADDED
@@ -0,0 +1,15 @@
1
+ ##
2
+ # Define the main module
3
+ module Ballista
4
+ class << self
5
+ ##
6
+ # Insert a helper .new() method for creating a new Projection object
7
+
8
+ def new(*args)
9
+ self::Projection.new(*args)
10
+ end
11
+ end
12
+ end
13
+
14
+ require 'ballista/version'
15
+ require 'ballista/projection'
@@ -0,0 +1,76 @@
1
+ require 'date'
2
+ require 'libledger'
3
+
4
+ module Ballista
5
+ ##
6
+ # Projection class for creating journals
7
+ class Projection
8
+ def initialize(params = {})
9
+ @entries = params[:entries]
10
+ end
11
+
12
+ def project(months)
13
+ start = Date.today + 1
14
+ finish = start >> months
15
+ entries = start.upto(finish).map { |date| parse_day(date) }
16
+ Ledger.new(entries: entries.flatten)
17
+ end
18
+
19
+ private
20
+
21
+ ##
22
+ # This method pads all months so their last day covers through 31
23
+ # This ensures all monthly events can trigger, even in shorter months
24
+ def get_days(date)
25
+ return [date.day] if date.month == date.next.month
26
+ date.day.upto(date.day + 3).to_a
27
+ end
28
+
29
+ def out_of_bounds?(entry, date)
30
+ if entry[:starts] && Date.parse(entry[:starts]) > date
31
+ true
32
+ elsif entry[:ends] && Date.parse(entry[:ends]) < date
33
+ true
34
+ else
35
+ false
36
+ end
37
+ end
38
+
39
+ def parse_day(date)
40
+ get_days(date).map do |fake_day|
41
+ calendar[fake_day].map do |entry|
42
+ next if out_of_bounds?(entry, date)
43
+ build_entry(entry, date)
44
+ end
45
+ end
46
+ end
47
+
48
+ def build_entry(entry, date)
49
+ Ledger::Entry.new(
50
+ date: date,
51
+ name: entry[:name],
52
+ state: '!',
53
+ actions: build_actions(entry)
54
+ )
55
+ end
56
+
57
+ def build_actions(entry)
58
+ entry[:actions].map { |name, amount| { name: name, amount: amount } }
59
+ end
60
+
61
+ def calendar
62
+ return @calendar if @calendar
63
+ @calendar = Hash.new { |h, k| h[k] = [] }
64
+ load_entries!
65
+ @calendar
66
+ end
67
+
68
+ def load_entries!
69
+ @entries.each do |entry|
70
+ dates = entry[:when]
71
+ dates = [dates] unless dates.is_a? Array
72
+ dates.each { |date| @calendar[date] << entry }
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,5 @@
1
+ ##
2
+ # Set the version (needed for Mercenary -v)
3
+ module Ballista
4
+ VERSION = '0.0.1'.freeze
5
+ end
@@ -0,0 +1 @@
1
+ require 'spec_helper'
@@ -0,0 +1,11 @@
1
+ if ENV['CI'] == 'true'
2
+ require 'simplecov'
3
+ require 'codecov'
4
+ SimpleCov.formatter = SimpleCov::Formatter::Codecov
5
+ SimpleCov.start do
6
+ add_filter '/spec/'
7
+ end
8
+ end
9
+
10
+ require 'rspec'
11
+ require 'ballista'
metadata ADDED
@@ -0,0 +1,174 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ballista
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Les Aker
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: libledger
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.0.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.0.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: mercenary
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.3.4
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.3.4
41
+ - !ruby/object:Gem::Dependency
42
+ name: cymbal
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.0.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.39.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.39.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 11.1.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 11.1.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: codecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.1.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.1.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 3.4.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 3.4.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: fuubar
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 2.0.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 2.0.0
125
+ description: Projection tool for Ledger format
126
+ email: me@lesaker.org
127
+ executables:
128
+ - ballista
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".prospectus"
134
+ - ".rspec"
135
+ - ".rubocop.yml"
136
+ - Gemfile
137
+ - LICENSE
138
+ - README.md
139
+ - Rakefile
140
+ - ballista.gemspec
141
+ - bin/ballista
142
+ - circle.yml
143
+ - lib/ballista.rb
144
+ - lib/ballista/projection.rb
145
+ - lib/ballista/version.rb
146
+ - spec/ballista_spec.rb
147
+ - spec/spec_helper.rb
148
+ homepage: https://github.com/akerl/ballista
149
+ licenses:
150
+ - MIT
151
+ metadata: {}
152
+ post_install_message:
153
+ rdoc_options: []
154
+ require_paths:
155
+ - lib
156
+ required_ruby_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ required_rubygems_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ requirements: []
167
+ rubyforge_project:
168
+ rubygems_version: 2.5.1
169
+ signing_key:
170
+ specification_version: 4
171
+ summary: Projection tool for Ledger format
172
+ test_files:
173
+ - spec/ballista_spec.rb
174
+ - spec/spec_helper.rb