Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/hiptest-publisher/string.rb
Instance Method Summary collapse
- #camelize ⇒ Object
- #camelize_lower ⇒ Object
- #clear_extension ⇒ Object
- #literate ⇒ Object
- #normalize ⇒ Object
- #normalize_lower ⇒ Object
- #underscore ⇒ Object
Instance Method Details
#camelize ⇒ Object
31 32 33 34 |
# File 'lib/hiptest-publisher/string.rb', line 31 def camelize normalized = self.normalize normalized.split('_').map {|w| w.empty? ? "" : "#{w[0].upcase}#{w[1..-1]}"}.join end |
#camelize_lower ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/hiptest-publisher/string.rb', line 36 def camelize_lower normalized = self.normalize normalized.split('_').enum_for(:each_with_index).map do |w, i| if w.empty? "" elsif i == 0 "#{w[0].downcase}#{w[1..-1]}" else "#{w[0].upcase}#{w[1..-1]}" end end.join end |
#clear_extension ⇒ Object
49 50 51 |
# File 'lib/hiptest-publisher/string.rb', line 49 def clear_extension self.split('.')[0] end |
#literate ⇒ Object
6 7 8 9 |
# File 'lib/hiptest-publisher/string.rb', line 6 def literate I18n.enforce_available_locales = false I18n.transliterate(self) end |
#normalize ⇒ Object
11 12 13 14 |
# File 'lib/hiptest-publisher/string.rb', line 11 def normalize literated = self.literate literated.strip.gsub(/\s+/, '_').gsub(/\W/, '') end |
#normalize_lower ⇒ Object
16 17 18 19 |
# File 'lib/hiptest-publisher/string.rb', line 16 def normalize_lower literated = self.literate literated.strip.gsub(/\s+/, '_').gsub(/\W/, '').downcase end |
#underscore ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/hiptest-publisher/string.rb', line 21 def underscore # based on: # http://stackoverflow.com/questions/1509915/converting-camel-case-to-underscore-case-in-ruby normalized = self.normalize normalized.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr("-", "_"). downcase end |