Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/hiptest-publisher/string.rb
Instance Method Summary collapse
- #camelize ⇒ Object
- #camelize_lower ⇒ Object
- #camelize_upper ⇒ Object
- #clear_extension ⇒ Object
- #literate ⇒ Object
- #normalize ⇒ Object
- #normalize_lower ⇒ Object
- #underscore ⇒ Object
Instance Method Details
#camelize ⇒ Object
30 31 32 33 |
# File 'lib/hiptest-publisher/string.rb', line 30 def camelize normalized = self.normalize normalized.split('_').map {|w| w.empty? ? "" : "#{w[0].upcase}#{w[1..-1]}"}.join end |
#camelize_lower ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/hiptest-publisher/string.rb', line 35 def camelize_lower camelized = self.camelize if camelized.empty? "" else "#{camelized[0].downcase}#{camelized[1..-1]}" end end |
#camelize_upper ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/hiptest-publisher/string.rb', line 44 def camelize_upper camelized = self.camelize if camelized.empty? "" else "#{camelized[0].upcase}#{camelized[1..-1]}" end end |
#clear_extension ⇒ Object
53 54 55 |
# File 'lib/hiptest-publisher/string.rb', line 53 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 |
# File 'lib/hiptest-publisher/string.rb', line 16 def normalize_lower self.normalize.downcase end |
#underscore ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/hiptest-publisher/string.rb', line 20 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 |