Class: String

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

Instance Method Summary collapse

Instance Method Details

#underscoreString

Converts a String object into a simple as used on an Amex::CardAccount object - the XML uses camelCase attributes, we want underscored ones which we can convert to symbol (e.g. cardProduct to card_product)

Returns:

  • (String)

    the reformatted string


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

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