Class: AzaharaSchemaCurrency::CurrencyAttribute
- Inherits:
-
AzaharaSchema::Attribute
- Object
- AzaharaSchema::Attribute
- AzaharaSchemaCurrency::CurrencyAttribute
- Defined in:
- lib/azahara_schema_currency/currency_attribute.rb
Instance Method Summary collapse
- #currency_code(entity) ⇒ Object
- #currency_code_col ⇒ Object
-
#initialize(model, name, type = 'currency', **options) ⇒ CurrencyAttribute
constructor
A new instance of CurrencyAttribute.
- #value(record) ⇒ Object
Constructor Details
#initialize(model, name, type = 'currency', **options) ⇒ CurrencyAttribute
Returns a new instance of CurrencyAttribute.
8 9 10 11 |
# File 'lib/azahara_schema_currency/currency_attribute.rb', line 8 def initialize(model, name, type='currency', **) super(model, name, type) @options = end |
Instance Method Details
#currency_code(entity) ⇒ Object
17 18 19 |
# File 'lib/azahara_schema_currency/currency_attribute.rb', line 17 def currency_code(entity) entity.try(currency_code_col) end |
#currency_code_col ⇒ Object
13 14 15 |
# File 'lib/azahara_schema_currency/currency_attribute.rb', line 13 def currency_code_col @options[:currency_code_method] || 'currency_code' end |
#value(record) ⇒ Object
21 22 23 24 25 |
# File 'lib/azahara_schema_currency/currency_attribute.rb', line 21 def value(record) val = super(record) val = BigDecimal(val.to_s.presence || 0) unless val.is_a?(BigDecimal) val end |