Class: String

Inherits:
Object show all
Defined in:
lib/rchoice/core_ext.rb

Instance Method Summary collapse

Instance Method Details

#safe_to_fObject



27
28
29
30
# File 'lib/rchoice/core_ext.rb', line 27

def safe_to_f
  raise "not valid number format #{self}" unless valid_number_format?
  to_f
end

#safe_to_iObject



23
24
25
26
# File 'lib/rchoice/core_ext.rb', line 23

def safe_to_i
  raise "not valid number format '#{self}'" unless valid_number_format?
  to_i
end

#valid_number_format?Boolean

Returns:

  • (Boolean)


18
19
20
21
22
# File 'lib/rchoice/core_ext.rb', line 18

def valid_number_format?
  return false if blank?
  return false unless self.strip =~ /^[0-9\.\-]+$/
  true
end