Class: Melitta::Coercers::Float
- Inherits:
-
Struct
- Object
- Struct
- Melitta::Coercers::Float
- Defined in:
- lib/melitta/coercers.rb
Instance Attribute Summary collapse
-
#input ⇒ Object
Returns the value of attribute input.
Instance Method Summary collapse
Instance Attribute Details
#input ⇒ Object
Returns the value of attribute input
44 45 46 |
# File 'lib/melitta/coercers.rb', line 44 def input @input end |
Instance Method Details
#output ⇒ Object
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
46 47 48 |
# File 'lib/melitta/coercers.rb', line 46 def valid? !! /\A\d+([,.]\d+)?\z/.match(input) end |