module Pico::StringInflections

Public Instance Methods

to_camel_case() click to toggle source
# File lib/pico/string_inflections.rb, line 4
def to_camel_case
  str = "_#{self}"
  str.gsub!(%r{_[a-z]}) { |snake| snake.slice(1).upcase }
  str.gsub!('/', '::')
  str
end
to_snake_case() click to toggle source
# File lib/pico/string_inflections.rb, line 11
def to_snake_case
  str = gsub '::', '/'
  # Convert FOOBar => FooBar
  str.gsub! %r{[[:upper:]]{2,}} do |uppercase|
    bit = uppercase[0]
    bit << uppercase[1...-1].downcase
    bit << uppercase[-1]
    bit
  end
  str.gsub! %r{[[:lower:]][[:upper:]]+[[:lower:]]} do |camel|
    bit = camel[0]
    bit << '_'
    bit << camel[1..-1].downcase
  end
  str.downcase!
  str
end