Sha256: 89e72b60b2b57b0a702e7a4f304ca24db8970bc82fc8605ec51396a458d4a4b5

Contents?: true

Size: 595 Bytes

Versions: 3

Compression:

Stored size: 595 Bytes

Contents

module DeadSimpleDb

  class SdbFloat

    include NegativeNumber

    DEFAULT_OPTS = {:digits => 8, :decimals => 2}

    def initialize(value, opts={})
      @opts = DEFAULT_OPTS.merge(opts)
      @value_before_cast = value
    end

    def casted
      @casted ||= @value_before_cast.to_f
    end

    def to_s
      @string ||= prepending_minus(casted.to_s) do |string|
          integer, decimal = *string.split('.')
          integer.rjust(@opts[:digits] - @opts[:decimals], '0') + '.' +
          decimal[0..@opts[:decimals] - 1].ljust(@opts[:decimals], '0')
      end
    end

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hungryblank-dead_simple_db-0.0.1 lib/dead_simple_db/datatypes/sdb_float.rb
hungryblank-dead_simple_db-0.0.2 lib/dead_simple_db/datatypes/sdb_float.rb
hungryblank-dead_simple_db-0.0.3 lib/dead_simple_db/datatypes/sdb_float.rb