Sha256: 1533fdc209123971772df28048b416881c855a8739b99e867465bff6c69c3f6b

Contents?: true

Size: 415 Bytes

Versions: 9

Compression:

Stored size: 415 Bytes

Contents

require "bigdecimal"
require "bigdecimal/util"

module Cascade
  module ComplexFields
    class Currency
      def call(value)
        value = normalized_value(value)
        value.to_d if valid?(value)
      end

      private

      def normalized_value(value)
        String(value).tr(",", ".").tr(" ", "")
      end

      def valid?(value)
        true if Float(value) rescue false
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
cascade-rb-0.2.3 lib/cascade/complex_fields/currency.rb
cascade-rb-0.2.2 lib/cascade/complex_fields/currency.rb
cascade-rb-0.2.1 lib/cascade/complex_fields/currency.rb
cascade-rb-0.2.0 lib/cascade/complex_fields/currency.rb
cascade-rb-0.1.5 lib/cascade/complex_fields/currency.rb
cascade-rb-0.1.4 lib/cascade/complex_fields/currency.rb
cascade-rb-0.1.2 lib/cascade/complex_fields/currency.rb
cascade-rb-0.1.1 lib/cascade/complex_fields/currency.rb
cascade-rb-0.1.0 lib/cascade/complex_fields/currency.rb