Class: DeathAndTaxes::Country
- Inherits:
-
Object
- Object
- DeathAndTaxes::Country
- Defined in:
- lib/death_and_taxes/country.rb
Instance Method Summary collapse
- #applicable_taxes(seller, buyer, date) ⇒ Object
- #applies_taxes?(from, to, date) ⇒ Boolean
- #build_tax(tax, date) ⇒ Object
-
#initialize(code, yml = nil) ⇒ Country
constructor
A new instance of Country.
- #parse(yml) ⇒ Object
Constructor Details
#initialize(code, yml = nil) ⇒ Country
Returns a new instance of Country.
4 5 6 7 8 9 |
# File 'lib/death_and_taxes/country.rb', line 4 def initialize code, yml = nil @taxes = {} @states = {} @code = code parse yml if yml end |
Instance Method Details
#applicable_taxes(seller, buyer, date) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/death_and_taxes/country.rb', line 21 def applicable_taxes seller, buyer, date if seller[:country] == buyer[:country] && seller[:country] == @code @states[seller[:state]].applicable_taxes buyer[:state], date else [] end end |
#applies_taxes?(from, to, date) ⇒ Boolean
29 30 31 |
# File 'lib/death_and_taxes/country.rb', line 29 def applies_taxes? from, to, date applicable_taxes(from, to, date).any? end |
#build_tax(tax, date) ⇒ Object
33 34 35 |
# File 'lib/death_and_taxes/country.rb', line 33 def build_tax tax, date @taxes[tax].try(:build, date) || @states.detect{|t, s| s.try(:build_tax, tax, date)}.try(:last).try(:build_tax, tax, date) end |
#parse(yml) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/death_and_taxes/country.rb', line 11 def parse yml yml['taxes'].each do |tax_name, infos| @taxes[tax_name] = TaxInfo.new(tax_name, infos) end yml['states'].each do |state_code, state_yml| @states[state_code] = State.new(state_code, state_yml) end end |