Sha256: 5435f7dcd61caaeb623efc3aafa6e907a262481ffe88621dfd79b7912444b038

Contents?: true

Size: 949 Bytes

Versions: 6

Compression:

Stored size: 949 Bytes

Contents

# frozen_string_literal: true

module Cmdlet
  # Inflection handling routines, eg. pluralize, singular, ordinalize
  module Inflection
    # PluralizeByNumber: Returns the plural form of the word based on a count
    class PluralizeByNumber < Cmdlet::BaseCmdlet
      #
      # @param [String] value - value - value to pluralize
      # @param [Int] count - count used to determine pluralization
      # @param [String] format - (Optional) what format should output be. :word, :number_word
      # @return [String] value and number are used to calculate plural/singular form
      def call(value, count, format)
        return '' if value.nil?

        count = count.to_i if count.is_a? String
        format = :word if format.nil?

        case format.to_sym
        when :number_word, :number_and_word
          "#{count} #{value.pluralize(count)}"
        else # aka :word
          value.pluralize(count)
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
cmdlet-0.4.2 lib/cmdlet/inflection/pluralize_by_number.rb
cmdlet-0.4.1 lib/cmdlet/inflection/pluralize_by_number.rb
cmdlet-0.4.0 lib/cmdlet/inflection/pluralize_by_number.rb
cmdlet-0.3.0 lib/cmdlet/inflection/pluralize_by_number.rb
cmdlet-0.2.1 lib/cmdlet/inflection/pluralize_by_number.rb
cmdlet-0.2.0 lib/cmdlet/inflection/pluralize_by_number.rb