Sha256: a1e4df822dff5067c564f97249946fe10960cc9f11f5538475dc45da8ae8c74d
Contents?: true
Size: 841 Bytes
Versions: 2
Compression:
Stored size: 841 Bytes
Contents
module DeathAndTaxes class State def initialize code, yml = nil @taxes = {} @code = code parse yml if yml end def parse yml ## # Builds a tax list for each taxes defined in this state yml['taxes'].each do |tax_name, infos| @taxes[tax_name] = TaxInfo.new(tax_name, infos) end @rules = yml['rules'] end 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 def build_tax tax, date if (i = @taxes[tax]) && i.cover?(date) i.build(date) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
death_and_taxes-0.0.5 | lib/death_and_taxes/state.rb |
death_and_taxes-0.0.4 | lib/death_and_taxes/state.rb |