Sha256: 548689c40d15598b01af06d574c5a99d74faa6db7a62b5d3c528b56d138245de

Contents?: true

Size: 744 Bytes

Versions: 45

Compression:

Stored size: 744 Bytes

Contents

# Author::    Ondřej Ezr  (mailto:oezr@msp.justice.cz)
# Copyright:: Copyright (c) 2018 Ministry of Justice
# License::   Distributes under license Open Source Licence pro Veřejnou Správu a Neziskový Sektor v.1

module AzaharaSchemaCurrency
  class CurrencyAttribute < AzaharaSchema::Attribute

    def initialize(model, name, type='currency', **options)
      super(model, name, type)
      @options = options
    end

    def currency_code_col
      @options[:currency_code_method] || 'currency_code'
    end

    def currency_code(entity)
      entity.try(currency_code_col)
    end

    def value(record)
      val = super(record)
      val = BigDecimal(val.to_s.presence || 0) unless val.is_a?(BigDecimal)
      val
    end

  end
end

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
egov_utils-1.4.1 lib/azahara_schema_currency/currency_attribute.rb
egov_utils-1.4.0 lib/azahara_schema_currency/currency_attribute.rb
egov_utils-1.3.0 lib/azahara_schema_currency/currency_attribute.rb
egov_utils-1.2.4 lib/azahara_schema_currency/currency_attribute.rb
egov_utils-1.2.3 lib/azahara_schema_currency/currency_attribute.rb
egov_utils-1.2.2 lib/azahara_schema_currency/currency_attribute.rb
egov_utils-1.2.1 lib/azahara_schema_currency/currency_attribute.rb
egov_utils-1.2.0 lib/azahara_schema_currency/currency_attribute.rb
egov_utils-1.1.1 lib/azahara_schema_currency/currency_attribute.rb
egov_utils-1.1.0 lib/azahara_schema_currency/currency_attribute.rb
egov_utils-1.0.3 lib/azahara_schema_currency/currency_attribute.rb
egov_utils-1.0.2 lib/azahara_schema_currency/currency_attribute.rb
egov_utils-1.0.1 lib/azahara_schema_currency/currency_attribute.rb
egov_utils-1.0.0 lib/azahara_schema_currency/currency_attribute.rb
egov_utils-0.7.5 lib/azahara_schema_currency/currency_attribute.rb
egov_utils-0.7.4 lib/azahara_schema_currency/currency_attribute.rb
egov_utils-0.7.3 lib/azahara_schema_currency/currency_attribute.rb
egov_utils-0.7.2 lib/azahara_schema_currency/currency_attribute.rb
egov_utils-0.7.1 lib/azahara_schema_currency/currency_attribute.rb
egov_utils-0.7.0 lib/azahara_schema_currency/currency_attribute.rb