module Kokkai::Utils::StringFormatter

Public Instance Methods

normalize() click to toggle source
# File lib/kokkai/utils/string_formatter.rb, line 22
def normalize()
  text = self
  if text =~ / /
    text.downcase
  elsif text =~ /-/
    text.gsub("-", " ").downcase
  elsif text =~ /_/
    text.gsub("_", " ").downcase
  else
    text.split(/(?=[A-Z])/).join(" ").downcase
  end
end
to_camel() click to toggle source
# File lib/kokkai/utils/string_formatter.rb, line 13
def to_camel()
  to_pascal().sub(/./) { $&.downcase }
end
to_chain() click to toggle source
# File lib/kokkai/utils/string_formatter.rb, line 5
def to_chain()
  normalize().gsub(" ", "-")
end
to_pascal() click to toggle source
# File lib/kokkai/utils/string_formatter.rb, line 17
def to_pascal()
  normalize().split.map { |e| e.capitalize }.join
end
to_snake() click to toggle source
# File lib/kokkai/utils/string_formatter.rb, line 9
def to_snake()
  normalize().gsub(" ", "_")
end