Module: Hivonic::Common::StringHelper

Included in:
String
Defined in:
lib/hivonic/common/string_helper.rb,
lib/hivonic/common/string_helper.rb

Instance Method Summary collapse

Instance Method Details

#classifyObject



15
16
17
# File 'lib/hivonic/common/string_helper.rb', line 15

def classify
  self.split('_').collect(&:capitalize).join
end

#randcaseObject



5
6
7
8
9
10
11
12
13
# File 'lib/hivonic/common/string_helper.rb', line 5

def randcase
  dup.split('').map do |char|
    if rand(1..10) > 5
      char.upcase
    else
      char.downcase
    end
  end.join
end

#titleizeObject



27
28
29
# File 'lib/hivonic/common/string_helper.rb', line 27

def titleize
  self.gsub(/\b('?[a-z])/) { $1.capitalize }
end

#titleize_wordsObject



31
32
33
# File 'lib/hivonic/common/string_helper.rb', line 31

def titleize_words
  self.gsub(/\w+/) { |s| s.capitalize }
end

#underscoreObject



19
20
21
22
23
24
25
# File 'lib/hivonic/common/string_helper.rb', line 19

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