Sha256: 82c333a2f172520a37aa611aae5b3a81b0064b0354f5258a85fb66198c8acfc1

Contents?: true

Size: 609 Bytes

Versions: 26

Compression:

Stored size: 609 Bytes

Contents

module Foobara
  module BuiltinTypes
    module Float
      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)
            string.to_f
          end
        end
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
foobara-0.0.26 projects/builtin_types/src/float/casters/string.rb
foobara-0.0.25 projects/builtin_types/src/float/casters/string.rb
foobara-0.0.24 projects/builtin_types/src/float/casters/string.rb
foobara-0.0.23 projects/builtin_types/src/float/casters/string.rb
foobara-0.0.22 projects/builtin_types/src/float/casters/string.rb
foobara-0.0.21 projects/builtin_types/src/float/casters/string.rb
foobara-0.0.20 projects/builtin_types/src/float/casters/string.rb
foobara-0.0.19 projects/builtin_types/src/float/casters/string.rb
foobara-0.0.18 projects/builtin_types/src/float/casters/string.rb
foobara-0.0.17 projects/builtin_types/src/float/casters/string.rb
foobara-0.0.16 projects/builtin_types/src/float/casters/string.rb
foobara-0.0.15 projects/builtin_types/src/float/casters/string.rb
foobara-0.0.14 projects/builtin_types/src/float/casters/string.rb
foobara-0.0.13 projects/builtin_types/src/float/casters/string.rb
foobara-0.0.12 projects/builtin_types/src/float/casters/string.rb
foobara-0.0.11 projects/builtin_types/src/float/casters/string.rb
foobara-0.0.10 projects/builtin_types/src/float/casters/string.rb
foobara-0.0.9 projects/builtin_types/src/float/casters/string.rb
foobara-0.0.8 projects/builtin_types/src/float/casters/string.rb
foobara-0.0.7 projects/builtin_types/src/float/casters/string.rb