Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/limelight/string.rb
Instance Method Summary collapse
-
#camalized(starting_case = :upper) ⇒ Object
Converts Ruby style names to Java style camal case.
-
#titleized(starting_case = :upper) ⇒ Object
Converts ruby style and camalcase strings into title strings where every word is capitalized and separated by a space.
-
#underscored ⇒ Object
Converts Java camel case names to ruby style underscored names.
Instance Method Details
#camalized(starting_case = :upper) ⇒ Object
Converts Ruby style names to Java style camal case.
"four_score".camalized # => "FourScore"
"and_seven_years".camalized(:lower) # => "andSevenYears"
8 9 10 11 12 |
# File 'lib/limelight/string.rb', line 8 def camalized(starting_case = :upper) value = self.downcase.gsub(/[_| ][a-z]/) { |match| match[-1..-1].upcase } value = value[0..0].upcase + value[1..-1] if starting_case == :upper return value end |
#titleized(starting_case = :upper) ⇒ Object
Converts ruby style and camalcase strings into title strings where every word is capitalized and separated by a space.
"four_score".titleized # => "Four Score"
30 31 32 33 34 |
# File 'lib/limelight/string.rb', line 30 def titleized(starting_case = :upper) value = self.gsub(/[a-z0-9][A-Z]/) { |match| "#{match[0..0]} #{match[-1..-1]}" } value = value.gsub(/[_| ][a-z]/) { |match| " #{match[-1..-1].upcase}" } return value[0..0].upcase + value[1..-1] end |
#underscored ⇒ Object
Converts Java camel case names to ruby style underscored names.
"FourScore".underscored # => "four_score"
"andSevenYears".underscored # => "and_seven_years"
19 20 21 22 23 |
# File 'lib/limelight/string.rb', line 19 def underscored value = self[0..0].downcase + self[1..-1] value = value.gsub(/[A-Z]/) { |cap| "_#{cap.downcase}" } return value end |