Sha256: bbed99f7942313efbf3c67cd17a020c6c14a59ae896b022205373ae2d8ffb219

Contents?: true

Size: 563 Bytes

Versions: 3

Compression:

Stored size: 563 Bytes

Contents

class Groupie
  class Group
    def initialize(name)
      @name = name
      @word_counts = {}
    end
    
    def words
      @word_counts.keys
    end

    # Add new words to the group.
    def add(*words)
      words.flatten.each do |word|
        add_word(word)
      end
      nil
    end

    # Return the count for a specific +word+.
    def count(word)
      @word_counts[word] || 0
    end

    # Add a single word and count it.
    def add_word(word)
      @word_counts[word] ||= 0
      @word_counts[word] += 1
    end
    private :add_word
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
groupie-0.2.2 lib/groupie/group.rb
groupie-0.1.1 lib/groupie/group.rb
groupie-0.1.0 lib/groupie/group.rb