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-4.0.32 lib/cassandra_object/types/decimal_type.rb
sessionm-cassandra_object-4.0.31 lib/cassandra_object/types/decimal_type.rb
sessionm-cassandra_object-4.0.30 lib/cassandra_object/types/decimal_type.rb
sessionm-cassandra_object-4.0.29 lib/cassandra_object/types/decimal_type.rb
sessionm-cassandra_object-4.0.28 lib/cassandra_object/types/decimal_type.rb
sessionm-cassandra_object-4.0.27 lib/cassandra_object/types/decimal_type.rb
sessionm-cassandra_object-4.0.26 lib/cassandra_object/types/decimal_type.rb
sessionm-cassandra_object-4.0.25 lib/cassandra_object/types/decimal_type.rb
sessionm-cassandra_object-4.0.24 lib/cassandra_object/types/decimal_type.rb
sessionm-cassandra_object-4.0.23 lib/cassandra_object/types/decimal_type.rb
sessionm-cassandra_object-4.0.22 lib/cassandra_object/types/decimal_type.rb
sessionm-cassandra_object-4.0.21 lib/cassandra_object/types/decimal_type.rb
sessionm-cassandra_object-4.0.20 lib/cassandra_object/types/decimal_type.rb
sessionm-cassandra_object-2.7.5 lib/cassandra_object/types/decimal_type.rb
sessionm-cassandra_object-2.7.4 lib/cassandra_object/types/decimal_type.rb
sessionm-cassandra_object-4.0.18 lib/cassandra_object/types/decimal_type.rb
sessionm-cassandra_object-4.0.17 lib/cassandra_object/types/decimal_type.rb
sessionm-cassandra_object-4.0.16 lib/cassandra_object/types/decimal_type.rb
sessionm-cassandra_object-4.0.15 lib/cassandra_object/types/decimal_type.rb
sessionm-cassandra_object-4.0.14 lib/cassandra_object/types/decimal_type.rb