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
- #classify ⇒ Object
- #randcase ⇒ Object
- #titleize ⇒ Object
- #titleize_words ⇒ Object
- #underscore ⇒ Object
Instance Method Details
#classify ⇒ Object
15 16 17 |
# File 'lib/hivonic/common/string_helper.rb', line 15 def classify self.split('_').collect(&:capitalize).join end |
#randcase ⇒ Object
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 |
#titleize ⇒ Object
27 28 29 |
# File 'lib/hivonic/common/string_helper.rb', line 27 def titleize self.gsub(/\b('?[a-z])/) { $1.capitalize } end |
#titleize_words ⇒ Object
31 32 33 |
# File 'lib/hivonic/common/string_helper.rb', line 31 def titleize_words self.gsub(/\w+/) { |s| s.capitalize } end |
#underscore ⇒ Object
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 |