Class: Melitta::Coercers::Float

Inherits:
Struct
  • Object
show all
Defined in:
lib/melitta/coercers.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#inputObject

Returns the value of attribute input

Returns:

  • (Object)

    the current value of input



44
45
46
# File 'lib/melitta/coercers.rb', line 44

def input
  @input
end

Instance Method Details

#outputObject



50
51
52
53
54
# File 'lib/melitta/coercers.rb', line 50

def output
  output = input
  output = input.gsub(',', '.') if /(\d)*,(\d)*/.match(input)
  output.to_f
end

#valid?Boolean

Returns:



46
47
48
# File 'lib/melitta/coercers.rb', line 46

def valid?
  !! /\A\d+([,.]\d+)?\z/.match(input)
end