Sha256: 8df2705a38b1f2adb437a63c097d9a184e208a130f70a9e8484fdc2939e5504f

Contents?: true

Size: 621 Bytes

Versions: 27

Compression:

Stored size: 621 Bytes

Contents

module Foobara
  module BuiltinTypes
    module BigDecimal
      module Casters
        class String < Value::Caster
          FLOAT_REGEX = /^-?\d+(\.\d+)?([eE]-?\d+)?$/

          def applicable?(value)
            value.is_a?(::String) && value =~ FLOAT_REGEX
          end

          def applies_message
            "be a string of digits with one decimal point optionally amongst " \
              "them and optionally with a minus sign in front and optionally an exponent denoted with e"
          end

          def cast(string)
            BigDecimal(string)
          end
        end
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
foobara-0.0.7 projects/builtin_types/src/big_decimal/casters/string.rb
foobara-0.0.6 projects/builtin_types/src/big_decimal/casters/string.rb
foobara-0.0.5 projects/builtin_types/src/big_decimal/casters/string.rb
foobara-0.0.4 projects/builtin_types/src/big_decimal/casters/string.rb
foobara-0.0.3 projects/builtin_types/src/big_decimal/casters/string.rb
foobara-0.0.2 projects/builtin_types/src/big_decimal/casters/string.rb
foobara-0.0.1 projects/builtin_types/src/big_decimal/casters/string.rb