Class: DeathAndTaxes::State
- Inherits:
-
Object
- Object
- DeathAndTaxes::State
- Defined in:
- lib/death_and_taxes/state.rb
Instance Method Summary collapse
- #applicable_taxes(to_state, date) ⇒ Object
- #build_tax(tax, date) ⇒ Object
-
#initialize(code, yml = nil) ⇒ State
constructor
A new instance of State.
- #parse(yml) ⇒ Object
Constructor Details
#initialize(code, yml = nil) ⇒ State
Returns a new instance of State.
4 5 6 7 8 |
# File 'lib/death_and_taxes/state.rb', line 4 def initialize code, yml = nil @taxes = {} @code = code parse yml if yml end |
Instance Method Details
#applicable_taxes(to_state, date) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/death_and_taxes/state.rb', line 20 def applicable_taxes to_state, date rule = @rules.select{|d| (d['starts']..d['ends']).cover? date}.first taxes = if to_state == @code && rule['same_state'] rule['same_state'] elsif rule['same_country'] rule['same_country'] else [] end [taxes].flatten end |
#build_tax(tax, date) ⇒ Object
32 33 34 35 36 |
# File 'lib/death_and_taxes/state.rb', line 32 def build_tax tax, date if (i = @taxes[tax]) && i.cover?(date) i.build(date) end end |