Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/freightrain/string_patch.rb
Instance Method Summary collapse
- #from_convention ⇒ Object
-
#to_convention ⇒ Object
TODO: maybe activesupport has something like this.
- #to_convention_sym ⇒ Object
Instance Method Details
#from_convention ⇒ Object
29 30 31 |
# File 'lib/freightrain/string_patch.rb', line 29 def from_convention return self.capitalize.gsub(/_./) { |s| s.delete("_").capitalize } end |
#to_convention ⇒ Object
TODO: maybe activesupport has something like this
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/freightrain/string_patch.rb', line 5 def to_convention return "" if self.empty? clone = self.clone first_letter = clone.slice!(0) result = first_letter.chr.downcase #fix, each_char seems not to be implemented #before 1.8.7 (0...clone.length).each do |index| letter = clone[index].chr if letter =~ /^[A-Z]/ result += "_" result += letter.downcase else result += letter end end return result.downcase end |
#to_convention_sym ⇒ Object
24 25 26 27 |
# File 'lib/freightrain/string_patch.rb', line 24 def to_convention_sym return nil if self.to_convention.empty? return self.to_convention.to_sym end |