Sha256: 91fe2c6e0e36d7827b78f378320c358470625be785f9de38d7cc8ae485ff813d

Contents?: true

Size: 542 Bytes

Versions: 1

Compression:

Stored size: 542 Bytes

Contents

class StringCases
  def self.snake_to_camel(str)
    str.to_s.split("_").map(&:capitalize).join("")
  end

  def self.camel_to_snake(str)
    str.to_s.gsub(/(.)([A-Z])/,'\1_\2').downcase
  end

  def self.pluralize(str)
    str = "#{str}"

    if str.match(/([^aeiouy]|qu)y$/i)
      str = str.gsub(/y\Z/, "ies")
    else
      str << "s"
    end

    str
  end

  def self.singularize(str)
    str = "#{str}"

    if str.end_with?("ies")
      str = str.gsub(/ies\Z/, "y")
    else
      str = str.gsub(/s\Z/, "")
    end

    str
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
string-cases-0.0.2 lib/string-cases.rb