Class String
In: lib/limelight/string.rb
Parent: Object
  • Copyright 2008-2009 8th Light, Inc. All Rights Reserved.
  • Limelight and all included source files are distributed under terms of the GNU LGPL.

Methods

Public Instance methods

Converts Ruby style names to Java style camal case.

  "four_score".camalized # => "FourScore"
  "and_seven_years".camalized(:lower) # => "andSevenYears"

[Source]

    # 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"

[Source]

    # 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"

[Source]

    # 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

[Validate]