module Subby::CaseChanger

CaseChanger is a module for converting strings from one case to another.

Public Class Methods

to_camelcase( str ) click to toggle source

Convert string to camel-case. @example

CaseChanger.to_camelcase("apple pie") # => "applePie"

@param str [String] Argument need only respond to to_s. @return [String]

# File lib/subby/case_changer.rb, line 18
def self.to_camelcase( str )
  str.to_s.camelize(:lower)
end
to_classcase( str ) click to toggle source

Convert string to class-case. @example

CaseChanger.to_classcase("applePie") # => "ApplePie"

to_classcase is also aliased as to_modulecase. @param str [String] Argument need only respond to to_s. @return [String]

# File lib/subby/case_changer.rb, line 28
def self.to_classcase( str )
  str.to_s.camelize(:upper)
end
to_constantcase( str ) click to toggle source

Convert string to constant-case. @example

CaseChanger.to_constantcase("applePie") # => "APPLE_PIE"

@param str [String] Argument need only respond to to_s. @return [String]

# File lib/subby/case_changer.rb, line 37
def self.to_constantcase( str )
  str.to_s.underscore.upcase
end
to_dashcase( str ) click to toggle source

Convert string to dash-case. @example

CaseChanger.to_constantcase("applePie") # => "apple-pie"

@param str [String] Argument need only respond to to_s. @return [String]

# File lib/subby/case_changer.rb, line 46
def self.to_dashcase( str )
  str.to_s.underscore.dasherize
end
to_lowercase( str ) click to toggle source

Convert string to lower-case. @example

CaseChanger.to_lowercase("applePie") # => "apple pie"

@param str [String] Argument need only respond to to_s. @return [String]

# File lib/subby/case_changer.rb, line 55
def self.to_lowercase( str )
  str.to_s.underscore.tr('_', ' ')
end
to_sentencecase( str ) click to toggle source

Convert string to sentence-case. @example

CaseChanger.to_sentencecase("applePie") # => "Apple pie"

@param str [String] Argument need only respond to to_s. @return [String]

# File lib/subby/case_changer.rb, line 64
def self.to_sentencecase( str )
  str.to_s.underscore.tr('_', ' ').capitalize
end
to_snakecase( str ) click to toggle source

Convert string to underscore-case. @example

CaseChanger.to_underscorecase("applePie") # => "apple_pie"

to_snakecase is also aliased as to_underscorecase. @param str [String] Argument need only respond to to_s. @return [String]

# File lib/subby/case_changer.rb, line 74
def self.to_snakecase( str )
  str.to_s.underscore
end
to_titlecase( str ) click to toggle source

Convert string to title-case. @example

CaseChanger.to_titlecase("applePie") # => "Apple Pie"

@param str [String] Argument need only respond to to_s. @return [String]

# File lib/subby/case_changer.rb, line 83
def self.to_titlecase( str )
  str.to_s.underscore.tr('_', ' ').split.map(&:capitalize).join(' ')
end
to_uppercase( str ) click to toggle source

Convert string to upper-case. @example

CaseChanger.to_uppercase("applePie") # => "APPLE PIE"

@param str [String] Argument need only respond to to_s. @return [String]

# File lib/subby/case_changer.rb, line 92
def self.to_uppercase( str )
  str.to_s.underscore.tr('_', ' ').upcase
end