Class: TaxCode
- Inherits:
-
Object
- Object
- TaxCode
- Defined in:
- lib/tax_code.rb,
lib/tax_code/version.rb
Constant Summary collapse
- VERSION =
"0.0.3"
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(path = '.') ⇒ TaxCode
constructor
A new instance of TaxCode.
- #taxed_only ⇒ Object
- #taxes ⇒ Object
- #worst(num = 25) ⇒ Object
Constructor Details
#initialize(path = '.') ⇒ TaxCode
Returns a new instance of TaxCode.
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/tax_code.rb', line 19 def initialize(path = '.') dir = path file = '.' unless File.directory? path dir = File.dirname path file = File.basename path end Dir.chdir(dir) do log = `git log --numstat -M #{file}`.encode('UTF-8', 'UTF-8', :invalid => :replace) raise 'Path has to be inside your git repository' if log == "" compute_history(log) end end |
Class Method Details
.taxed_only(path = '.') ⇒ Object
14 15 16 |
# File 'lib/tax_code.rb', line 14 def taxed_only(path = '.') TaxCode.new(path).taxed_only end |
Instance Method Details
#taxed_only ⇒ Object
44 45 46 |
# File 'lib/tax_code.rb', line 44 def taxed_only taxes.select{ |_, t| t > 0 } end |
#taxes ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/tax_code.rb', line 33 def taxes @hist.inject({}) do |res, (f, changes)| size, tax = changes[0][1], 0 changes[1..-1].each do |c| tax += score(size, *c) size += c[1] - c[2] end size > 0 ? res.merge(f => [tax.to_i, 0].max) : res end end |
#worst(num = 25) ⇒ Object
48 49 50 |
# File 'lib/tax_code.rb', line 48 def worst(num = 25) taxed_only.sort_by(&:last).last(num).reverse end |