Sha256: c359f1bacf0314b8be0fdc0b5b1fa947594b287e09e72e8def8770f4670269af

Contents?: true

Size: 863 Bytes

Versions: 11

Compression:

Stored size: 863 Bytes

Contents

require 'caruby/active_support/inflector'

class String
  # @param [Numeric] quantity the amount qualifier
  # @return this String qualified by a plural if the quantity is not 1
  # @example
  #   "rose".quantify(3) #=> "roses"
  #   "rose".quantify(1 #=> "rose"
  def quantify(quantity)
    raise ArgumentError.new("Missing quantity argument") if quantity.nil?
    "#{quantity} #{quantity == 1 ? self : pluralize}"
  end
  
  # @return this String with the first letter capitalized and other letters preserved.
  # @example
  #   "rosesAreRed".capitalize_first #=> "RosesAreRed"
  def capitalize_first
    sub(/(?:^)(.)/) { $1.upcase }
  end
  
  # @return this String with the first letter decapitalized and other letters preserved.
  # @example
  #   "RosesAreRed".decapitalize #=> "rosesAreRed"
  def decapitalize
    sub(/(?:^)(.)/) { $1.downcase }
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
caruby-core-1.5.5 lib/caruby/util/inflector.rb
caruby-core-1.5.4 lib/caruby/util/inflector.rb
caruby-core-1.5.3 lib/caruby/util/inflector.rb
caruby-core-1.5.2 lib/caruby/util/inflector.rb
caruby-core-1.5.1 lib/caruby/util/inflector.rb
caruby-core-1.4.9 lib/caruby/util/inflector.rb
caruby-core-1.4.7 lib/caruby/util/inflector.rb
caruby-core-1.4.6 lib/caruby/util/inflector.rb
caruby-core-1.4.5 lib/caruby/util/inflector.rb
caruby-core-1.4.4 lib/caruby/util/inflector.rb
caruby-core-1.4.3 lib/caruby/util/inflector.rb