Class: DeathAndTaxes::TaxInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/death_and_taxes/tax_info.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, yml = nil) ⇒ TaxInfo

Returns a new instance of TaxInfo.



3
4
5
6
# File 'lib/death_and_taxes/tax_info.rb', line 3

def initialize name, yml = nil
  @name = name
  parse yml if yml
end

Instance Method Details

#build(date) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/death_and_taxes/tax_info.rb', line 18

def build date
  if v = @versions.detect{ |version| version.cover?(date) }
    t = Tax.new :name => @name, :percentage => v.percentage
    t.tax = DeathAndTaxes.build(v.apply_on, date) if v.apply_on
    t
  end
end

#cover?(date) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/death_and_taxes/tax_info.rb', line 14

def cover? date
  @versions.any?{ |v| v.cover? date }
end

#parse(yml) ⇒ Object



8
9
10
11
12
# File 'lib/death_and_taxes/tax_info.rb', line 8

def parse yml
  @versions = yml['versions'].collect do |version|
    TaxVersion.new(version)
  end
end