| Class | String |
| In: |
lib/limelight/string.rb
|
| Parent: | Object |
Converts Ruby style names to Java style camal case.
"four_score".camalized # => "FourScore" "and_seven_years".camalized(:lower) # => "andSevenYears"
# File lib/limelight/string.rb, line 11
11: def camalized(starting_case = :upper)
12: value = self.downcase.gsub(/[_| |\-][a-z]/) { |match| match[-1..-1].upcase }
13: value = value[0..0].upcase + value[1..-1] if starting_case == :upper
14: return value
15: end
Converts ruby style and camalcase strings into title strings where every word is capitalized and separated by a space.
"four_score".titleized # => "Four Score"
# File lib/limelight/string.rb, line 33
33: def titleized(starting_case = :upper)
34: value = self.gsub(/[a-z0-9][A-Z]/) { |match| "#{match[0..0]} #{match[-1..-1]}" }
35: value = value.gsub(/[_| ][a-z]/) { |match| " #{match[-1..-1].upcase}" }
36: return value[0..0].upcase + value[1..-1]
37: end
Converts Java camel case names to ruby style underscored names.
"FourScore".underscored # => "four_score" "andSevenYears".underscored # => "and_seven_years"
# File lib/limelight/string.rb, line 22
22: def underscored
23: value = self[0..0].downcase + self[1..-1]
24: value = value.gsub(/[A-Z]/) { |cap| "_#{cap.downcase}" }
25: return value
26: end