Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/spektr/core_ext/string.rb

Instance Method Summary collapse

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)


2
3
4
# File 'lib/spektr/core_ext/string.rb', line 2

def blank?
  nil? || self == ""
end

#underscoreObject



6
7
8
9
10
11
12
13
14
15
# File 'lib/spektr/core_ext/string.rb', line 6

def underscore
  camel_cased_word = self
  return camel_cased_word.to_s unless /[A-Z-]|::/.match?(camel_cased_word)
  word = camel_cased_word.to_s.gsub("::", "/")
  word.gsub!(/(?:(?<=([A-Za-z\d]))|\b)((?=a))(?=\b|[^a-z])/) { "#{$1 && '_' }#{$2.downcase}" }
  word.gsub!(/([A-Z]+)(?=[A-Z][a-z])|([a-z\d])(?=[A-Z])/) { ($1 || $2) << "_" }
  word.tr!("-", "_")
  word.downcase!
  word
end