Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/beyond_api/ext.rb

Instance Method Summary collapse

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/beyond_api/ext.rb', line 29

def blank?
  respond_to?(:empty?) ? !!empty? : !self
end

#camelize(uppercase_first_letter = true) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/beyond_api/ext.rb', line 41

def camelize(uppercase_first_letter = true)
  string = self
  if uppercase_first_letter
    string = string.sub(/^[a-z\d]*/, &:capitalize)
  else
    string = string.sub(/^(?:(?=\b|[A-Z_])|\w)/, &:downcase)
  end
  string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }.gsub("/", "::")
end

#underscoreObject



33
34
35
36
37
38
39
# File 'lib/beyond_api/ext.rb', line 33

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