Class: JSONVAT::Country
- Inherits:
-
Object
- Object
- JSONVAT::Country
- Defined in:
- lib/json_vat/country.rb
Instance Method Summary collapse
- #code ⇒ Object
- #country_code ⇒ Object
-
#initialize(attributes) ⇒ Country
constructor
A new instance of Country.
- #name ⇒ Object
- #period_on(date) ⇒ Object
- #periods ⇒ Object
- #rate(type = :standard) ⇒ Object
- #rate_on(date, type = :standard) ⇒ Object
Constructor Details
#initialize(attributes) ⇒ Country
Returns a new instance of Country.
6 7 8 |
# File 'lib/json_vat/country.rb', line 6 def initialize(attributes) @attributes = attributes end |
Instance Method Details
#code ⇒ Object
18 19 20 |
# File 'lib/json_vat/country.rb', line 18 def code @attributes['code'] end |
#country_code ⇒ Object
14 15 16 |
# File 'lib/json_vat/country.rb', line 14 def country_code @attributes['country_code'] end |
#name ⇒ Object
10 11 12 |
# File 'lib/json_vat/country.rb', line 10 def name @attributes['name'] end |
#period_on(date) ⇒ Object
26 27 28 |
# File 'lib/json_vat/country.rb', line 26 def period_on(date) periods.select { |p| p.effective_from <= date }.sort_by(&:effective_from).last end |
#periods ⇒ Object
22 23 24 |
# File 'lib/json_vat/country.rb', line 22 def periods @periods ||= @attributes['periods'].map { |p| Period.new(self, p) } end |
#rate(type = :standard) ⇒ Object
38 39 40 |
# File 'lib/json_vat/country.rb', line 38 def rate(type = :standard) rate_on(Date.today, type) end |
#rate_on(date, type = :standard) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/json_vat/country.rb', line 30 def rate_on(date, type = :standard) if period = period_on(date) period.rates[type.to_s] else nil end end |