Class: Kafo::DataTypes::Numeric

Inherits:
Kafo::DataType show all
Defined in:
lib/kafo/data_types/numeric.rb

Instance Method Summary collapse

Methods inherited from Kafo::DataType

#condition_value, #dump_default, #multivalued?, new_from_string, parse_hash, register_type, split_arguments, #to_s, types, unregister_type

Instance Method Details

#typecast(value) ⇒ Object



4
5
6
# File 'lib/kafo/data_types/numeric.rb', line 4

def typecast(value)
  value =~ /\d+/ ? value.to_f : value
end

#valid?(input, errors = []) ⇒ Boolean

Returns:



8
9
10
11
# File 'lib/kafo/data_types/numeric.rb', line 8

def valid?(input, errors = [])
  errors << "#{input.inspect} is not a valid number" unless input.is_a?(::Integer) || input.is_a?(::Float)
  return errors.empty?
end