Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/amex/utils.rb

Instance Method Summary collapse

Instance Method Details

#to_boolObject

Raises:

  • (ArgumentError)


10
11
12
13
14
# File 'lib/amex/utils.rb', line 10

def to_bool
  return true if self == true || self =~ (/(true|t|yes|y|1)$/i)
  return false if self == false || self.blank? || self =~ (/(false|f|no|n|0)$/i)
  raise ArgumentError.new("invalid value for Boolean: \"#{self}\"")
end

#underscoreObject



2
3
4
5
6
7
8
# File 'lib/amex/utils.rb', line 2

def underscore
  self.gsub(/::/, '/').
  gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
  gsub(/([a-z\d])([A-Z])/,'\1_\2').
  tr("-", "_").
  downcase
end