Class: Xrechnung::Currency

Inherits:
Struct
  • Object
show all
Defined in:
lib/xrechnung/currency.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#currency_idObject

Returns the value of attribute currency_id

Returns:

  • (Object)

    the current value of currency_id



5
6
7
# File 'lib/xrechnung/currency.rb', line 5

def currency_id
  @currency_id
end

#valueObject

Returns the value of attribute value

Returns:

  • (Object)

    the current value of value



5
6
7
# File 'lib/xrechnung/currency.rb', line 5

def value
  @value
end

Class Method Details

.check_matching_attributes(one, other) ⇒ Object

Raises:

  • (ArgumentError)


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

Raises:

  • (ArgumentError)


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_sObject



6
7
8
# File 'lib/xrechnung/currency.rb', line 6

def value_to_s
  format("%0.2f", value)
end

#xml_argsObject



10
11
12
# File 'lib/xrechnung/currency.rb', line 10

def xml_args
  [value_to_s, { currencyID: currency_id }]
end