module Rosetta::Support

Public Instance Methods

camelize() click to toggle source
# File lib/rosetta/support/string_refinement.rb, line 8
def camelize
  case_components.map(&:capitalize).join
end
capitalize() click to toggle source
# File lib/rosetta/support/string_refinement.rb, line 16
def capitalize
  self[0].upcase + self[1..-1].downcase
end
case_components() click to toggle source
# File lib/rosetta/support/string_refinement.rb, line 20
def case_components
  full_caps_word = "[A-Z0-9]+(?![a-z])"
  titlecase_word = "[A-Z0-9][a-z0-9]*"
  lowercase_word = "(?!<[A-Z0-9])[a-z0-9]*"
  separator      = "[\w_-]"
  word           = "(#{full_caps_word})|(#{titlecase_word}|(#{lowercase_word})"
  components     = self.scan(/(?:#{word})#{separator}?)/)

  # HACK: Removing scan weirdness... there's probably a better way to do
  # this. Maybe stringscanner ?
  components.map { |component| component.reject { |e| e == '' || e.nil? }.uniq }.flatten
end
titleize() click to toggle source
# File lib/rosetta/support/string_refinement.rb, line 12
def titleize
  case_components.map(&:capitalize).join(' ')
end
underscore() click to toggle source
# File lib/rosetta/support/string_refinement.rb, line 4
def underscore
  case_components.map(&:downcase).join('_')
end