Class: TaxJp::ConsumptionTax
- Inherits:
-
Object
- Object
- TaxJp::ConsumptionTax
- Defined in:
- lib/tax_jp/consumption_tax.rb
Constant Summary collapse
Instance Attribute Summary collapse
-
#local ⇒ Object
readonly
Returns the value of attribute local.
-
#national ⇒ Object
readonly
Returns the value of attribute national.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
-
#valid_from ⇒ Object
readonly
Returns the value of attribute valid_from.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(valid_from, values) ⇒ ConsumptionTax
constructor
A new instance of ConsumptionTax.
- #local_percent ⇒ Object
- #national_percent ⇒ Object
- #total_percent ⇒ Object
Constructor Details
#initialize(valid_from, values) ⇒ ConsumptionTax
Returns a new instance of ConsumptionTax.
11 12 13 14 15 16 |
# File 'lib/tax_jp/consumption_tax.rb', line 11 def initialize(valid_from, values) @valid_from = valid_from @national = values['national'] @local = values['local'] @total = values['total'] end |
Instance Attribute Details
#local ⇒ Object (readonly)
Returns the value of attribute local.
9 10 11 |
# File 'lib/tax_jp/consumption_tax.rb', line 9 def local @local end |
#national ⇒ Object (readonly)
Returns the value of attribute national.
9 10 11 |
# File 'lib/tax_jp/consumption_tax.rb', line 9 def national @national end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
9 10 11 |
# File 'lib/tax_jp/consumption_tax.rb', line 9 def total @total end |
#valid_from ⇒ Object (readonly)
Returns the value of attribute valid_from.
8 9 10 |
# File 'lib/tax_jp/consumption_tax.rb', line 8 def valid_from @valid_from end |
Class Method Details
.all ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/tax_jp/consumption_tax.rb', line 18 def self.all ret = [] @@consumption_taxes.each do |valid_from, values| ret << ConsumptionTax.new(valid_from, values) end ret end |
.rate_on(date, options = {}) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/tax_jp/consumption_tax.rb', line 26 def self.rate_on(date, = {}) if date.is_a?(String) date = Date.parse(date) end ret = 0 @@consumption_taxes.reverse_each do |valid_from, rate| ret = rate['total'] break if date >= valid_from end if [:percent] ret *= 100 end ret end |
Instance Method Details
#local_percent ⇒ Object
48 49 50 |
# File 'lib/tax_jp/consumption_tax.rb', line 48 def local_percent local * 100 end |
#national_percent ⇒ Object
44 45 46 |
# File 'lib/tax_jp/consumption_tax.rb', line 44 def national_percent national * 100 end |
#total_percent ⇒ Object
52 53 54 |
# File 'lib/tax_jp/consumption_tax.rb', line 52 def total_percent total * 100 end |