File: big_decimal.rb

package info (click to toggle)
ruby-origin 2.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 248 kB
  • sloc: ruby: 1,196; makefile: 3
file content (33 lines) | stat: -rw-r--r-- 812 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# encoding: utf-8
require "bigdecimal"

module Origin
  module Extensions

    # The big decimal module adds custom behaviour for Origin onto the
    # BigDecimal class.
    module BigDecimal
      module ClassMethods

        # Evolves the big decimal into a MongoDB friendly value - in this case
        # a string.
        #
        # @example Evolve the big decimal
        #   BigDecimal.evolve(decimal)
        #
        # @param [ BigDecimal ] object The object to convert.
        #
        # @return [ String ] The big decimal as a string.
        #
        # @since 1.0.0
        def evolve(object)
          __evolve__(object) do |obj|
            obj ? obj.to_s : obj
          end
        end
      end
    end
  end
end

::BigDecimal.__send__(:extend, Origin::Extensions::BigDecimal::ClassMethods)