Class: Odin::Types::OdinCurrency
- Defined in:
- lib/odin/types/values.rb
Instance Attribute Summary collapse
-
#currency_code ⇒ Object
readonly
Returns the value of attribute currency_code.
-
#decimal_places ⇒ Object
readonly
Returns the value of attribute decimal_places.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Attributes inherited from OdinValue
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(value, currency_code: nil, decimal_places: 2, raw: nil, **kwargs) ⇒ OdinCurrency
constructor
A new instance of OdinCurrency.
- #to_s ⇒ Object
- #type ⇒ Object
- #with_directives(dirs) ⇒ Object
- #with_modifiers(mods) ⇒ Object
Methods inherited from OdinValue
#array?, #binary?, #boolean?, #confidential?, #currency?, #date?, #deprecated?, #duration?, #integer?, #null?, #number?, #numeric?, #object?, #percent?, #reference?, #required?, #string?, #temporal?, #time?, #timestamp?, #verb?
Constructor Details
#initialize(value, currency_code: nil, decimal_places: 2, raw: nil, **kwargs) ⇒ OdinCurrency
Returns a new instance of OdinCurrency.
221 222 223 224 225 226 227 228 |
# File 'lib/odin/types/values.rb', line 221 def initialize(value, currency_code: nil, decimal_places: 2, raw: nil, **kwargs) super(**kwargs) @value = value.is_a?(BigDecimal) ? value : BigDecimal(value.to_s) @currency_code = currency_code&.freeze @decimal_places = decimal_places @raw = raw&.freeze freeze end |
Instance Attribute Details
#currency_code ⇒ Object (readonly)
Returns the value of attribute currency_code.
219 220 221 |
# File 'lib/odin/types/values.rb', line 219 def currency_code @currency_code end |
#decimal_places ⇒ Object (readonly)
Returns the value of attribute decimal_places.
219 220 221 |
# File 'lib/odin/types/values.rb', line 219 def decimal_places @decimal_places end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
219 220 221 |
# File 'lib/odin/types/values.rb', line 219 def raw @raw end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
219 220 221 |
# File 'lib/odin/types/values.rb', line 219 def value @value end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
232 233 234 235 |
# File 'lib/odin/types/values.rb', line 232 def ==(other) other.is_a?(OdinCurrency) && value == other.value && currency_code == other.currency_code end |
#hash ⇒ Object
238 239 240 |
# File 'lib/odin/types/values.rb', line 238 def hash [ValueType::CURRENCY, value, currency_code].hash end |
#to_s ⇒ Object
242 243 244 245 |
# File 'lib/odin/types/values.rb', line 242 def to_s s = raw || value.to_s("F") currency_code ? "#{s}:#{currency_code}" : s end |
#with_directives(dirs) ⇒ Object
252 253 254 255 |
# File 'lib/odin/types/values.rb', line 252 def with_directives(dirs) OdinCurrency.new(value, currency_code: currency_code, decimal_places: decimal_places, raw: raw, modifiers: modifiers, directives: dirs) end |
#with_modifiers(mods) ⇒ Object
247 248 249 250 |
# File 'lib/odin/types/values.rb', line 247 def with_modifiers(mods) OdinCurrency.new(value, currency_code: currency_code, decimal_places: decimal_places, raw: raw, modifiers: mods, directives: directives) end |