Class: Xrechnung::Currency
- Inherits:
-
Struct
- Object
- Struct
- Xrechnung::Currency
- Defined in:
- lib/xrechnung/currency.rb
Instance Attribute Summary collapse
-
#currency_id ⇒ Object
Returns the value of attribute currency_id.
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#currency_id ⇒ Object
Returns the value of attribute currency_id
5 6 7 |
# File 'lib/xrechnung/currency.rb', line 5 def currency_id @currency_id end |
#value ⇒ Object
Returns the value of attribute value
5 6 7 |
# File 'lib/xrechnung/currency.rb', line 5 def value @value end |
Class Method Details
.check_matching_attributes(one, other) ⇒ Object
14 15 16 17 18 |
# File 'lib/xrechnung/currency.rb', line 14 def self.check_matching_attributes(one, other) raise ArgumentError, "other must be a Currency" unless one.is_a? Currency raise ArgumentError, "other must be a Currency" unless other.is_a? Currency raise ArgumentError, "currency_id must match" unless one.currency_id == other.currency_id end |
.EUR(value) ⇒ Object
32 33 34 35 36 |
# File 'lib/xrechnung/currency.rb', line 32 def EUR(value) raise ArgumentError, "value must respond to :to_d" unless value.respond_to? :to_d Currency.new(currency_id: "EUR", value: value.to_d) end |
Instance Method Details
#+(other) ⇒ Object
20 21 22 23 |
# File 'lib/xrechnung/currency.rb', line 20 def +(other) self.class.check_matching_attributes(self, other) Currency.new(currency_id: currency_id, value: value + other.value) end |
#-(other) ⇒ Object
25 26 27 28 |
# File 'lib/xrechnung/currency.rb', line 25 def -(other) self.class.check_matching_attributes(self, other) Currency.new(currency_id: currency_id, value: value - other.value) end |
#value_to_s ⇒ Object
6 7 8 |
# File 'lib/xrechnung/currency.rb', line 6 def value_to_s format("%0.2f", value) end |
#xml_args ⇒ Object
10 11 12 |
# File 'lib/xrechnung/currency.rb', line 10 def xml_args [value_to_s, { currencyID: currency_id }] end |