Sha256: 1c52704da38457dd25a3823da0bd6319e49d8fd77a4a8226061c80a21ad5cf3a

Contents?: true

Size: 616 Bytes

Versions: 8

Compression:

Stored size: 616 Bytes

Contents

module Mack
  module ViewHelpers
    module StringHelpers
      
      # Takes a count integer and a word and returns a phrase containing the count
      # and the correct inflection of the word.
      # 
      # Examples:
      #   pluralize_word(0, "error") # => "0 errors"
      #   pluralize_word(1, "error") # => "1 error"
      #   pluralize_word(2, "error") # => "2 errors"
      def pluralize_word(count, word)
        if count.to_i == 1
          "#{count} #{word.singular}"
        else
          "#{count} #{word.plural}"
        end
      end
      
    end # StringHelpers
  end # ViewHelpers
end # Mack

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
mack-0.5.5.2 lib/view_helpers/string_helpers.rb
mack-0.5.0 lib/sea_level/helpers/view_helpers/string_helpers.rb
mack-0.5.5.1 lib/view_helpers/string_helpers.rb
mack-0.5.5.3 lib/view_helpers/string_helpers.rb
mack-0.5.5.4 lib/view_helpers/string_helpers.rb
mack-0.6.0.1 lib/view_helpers/string_helpers.rb
mack-0.6.0 lib/view_helpers/string_helpers.rb
mack-0.5.5 lib/view_helpers/string_helpers.rb