Sha256: 3387c948232b502c989a847b30a3dd8e8ae160f4cf42967e1b4b9fa431870835

Contents?: true

Size: 1.32 KB

Versions: 15

Compression:

Stored size: 1.32 KB

Contents

module English # :nodoc:

  # = English Nouns Number Inflection.
  #
  # This module provides english singular <-> plural noun inflections.
  module Inflect # :nodoc:

    class << self

      # Convert an English word from plurel to singular.
      #
      #   "boys".singular      #=> boy
      #   "tomatoes".singular  #=> tomato
      #
      def singular(word)
        if result = singular_of[word]
          return result.dup
        end
        result = word.dup
        singularization_rules.each do |(match, replacement)|
          break if result.gsub!(match, replacement)
        end
        # Mack: cache the result of the translation:
        singular_of[word] = result unless word == result
        return result
      end
      
      # Convert an English word from singular to plurel.
      #
      #   "boy".plural     #=> boys
      #   "tomato".plural  #=> tomatoes
      #
      def plural(word)
        if result = plural_of[word]
          return result.dup
        end
        #return self.dup if /s$/ =~ self # ???
        result = word.dup
        pluralization_rules.each do |(match, replacement)|
          break if result.gsub!(match, replacement)
        end
        # Mack: cache the result of the translation:
        plural_of[word] = result unless word == result
        return result
      end

    end

  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
mack-facets-0.6.0.1 lib/english_extensions/inflect.rb
mack-facets-0.6.1.1 lib/mack-facets/english_extensions/inflect.rb
mack-facets-0.6.0 lib/english_extensions/inflect.rb
mack-facets-0.7.0 lib/mack-facets/english_extensions/inflect.rb
mack-facets-0.7.0.1 lib/mack-facets/english_extensions/inflect.rb
mack-facets-0.7.1 lib/mack-facets/english_extensions/inflect.rb
mack-facets-0.7.1.1 lib/mack-facets/english_extensions/inflect.rb
mack-facets-0.8.0.1 lib/mack-facets/english_extensions/inflect.rb
mack-facets-0.8.0.2 lib/mack-facets/english_extensions/inflect.rb
mack-facets-0.8.0.3 lib/mack-facets/english_extensions/inflect.rb
mack-facets-0.6.1 lib/mack-facets/english_extensions/inflect.rb
mack-facets-0.6.1.2 lib/mack-facets/english_extensions/inflect.rb
mack-facets-0.8.0.101 lib/mack-facets/english_extensions/inflect.rb
mack-facets-0.8.0 lib/mack-facets/english_extensions/inflect.rb
mack-facets-0.8.1 lib/mack-facets/english_extensions/inflect.rb