Sha256: c367e43eefbf6913b0f007af017f4a370f4bbe8998f5dade8182534bef01fd7a

Contents?: true

Size: 709 Bytes

Versions: 107

Compression:

Stored size: 709 Bytes

Contents

module CassandraObject
  module Types
    module DecimalType
      def encode(value)
        return nil if value.nil?
        raise ArgumentError.new("#{self} requires a Numeric") unless value.kind_of?(Numeric)
        value.to_s
      end
      module_function :encode

      def decode(value, options={})
        return nil if value.nil?
        value = value.to_s if value.kind_of?(Numeric)
        raise ArgumentError.new("Cannot convert #{value} into a BigDecimal") unless value.kind_of?(String)
        if options[:precision].present?
          BigDecimal.new(value, options[:precision])
        else
          BigDecimal.new(value)
        end
      end
      module_function :decode
    end
  end
end

Version data entries

107 entries across 107 versions & 1 rubygems

Version Path
sessionm-cassandra_object-2.3.9 lib/cassandra_object/types/decimal_type.rb
sessionm-cassandra_object-2.3.8 lib/cassandra_object/types/decimal_type.rb
sessionm-cassandra_object-2.3.6 lib/cassandra_object/types/decimal_type.rb
sessionm-cassandra_object-2.3.5 lib/cassandra_object/types/decimal_type.rb
sessionm-cassandra_object-2.3.4 lib/cassandra_object/types/decimal_type.rb
sessionm-cassandra_object-2.3.3 lib/cassandra_object/types/decimal_type.rb
sessionm-cassandra_object-2.3.2 lib/cassandra_object/types/decimal_type.rb
sessionm-cassandra_object-2.3.1 lib/cassandra_object/types/decimal_type.rb
sessionm-cassandra_object-2.3.0 lib/cassandra_object/types/decimal_type.rb
sessionm-cassandra_object-2.2.55 lib/cassandra_object/types/decimal_type.rb
sessionm-cassandra_object-2.2.54 lib/cassandra_object/types/decimal_type.rb
sessionm-cassandra_object-2.2.53 lib/cassandra_object/types/decimal_type.rb
sessionm-cassandra_object-2.2.52 lib/cassandra_object/types/decimal_type.rb
sessionm-cassandra_object-2.2.51 lib/cassandra_object/types/decimal_type.rb
sessionm-cassandra_object-2.2.50 lib/cassandra_object/types/decimal_type.rb
sessionm-cassandra_object-2.2.49 lib/cassandra_object/types/decimal_type.rb
sessionm-cassandra_object-2.2.48 lib/cassandra_object/types/decimal_type.rb
sessionm-cassandra_object-2.2.47 lib/cassandra_object/types/decimal_type.rb
sessionm-cassandra_object-2.2.46 lib/cassandra_object/types/decimal_type.rb
sessionm-cassandra_object-2.2.45 lib/cassandra_object/types/decimal_type.rb