Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/eveapi/util.rb

Overview

Utility String methods

Instance Method Summary collapse

Instance Method Details

#camelizeString

Camelize String

Returns:

  • (String)

    Camelized String



61
62
63
# File 'lib/eveapi/util.rb', line 61

def camelize
  split('_').each(&:capitalize!).join('')
end

#underscoreString

Snake Case a Camelized String

Returns:

  • (String)

    Snake Cased version of the String



68
69
70
71
72
73
74
75
76
# File 'lib/eveapi/util.rb', line 68

def underscore
  return self unless self =~ /[A-Z-]|::/
  word = to_s.gsub(/::/, '/')
  word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
  word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
  word.tr!('-', '_')
  word.downcase!
  word
end