Class: Groupie::Group

Inherits:
Object
  • Object
show all
Defined in:
lib/groupie/group.rb

Overview

Group represents a group or category that words can be classified into.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, groupie) ⇒ Group

Returns a new instance of Group.



8
9
10
11
12
13
# File 'lib/groupie/group.rb', line 8

def initialize(name, groupie)
  @name = name
  @groupie = groupie
  @word_counts = {}
  @total_word_count = 0
end

Instance Attribute Details

#total_word_countObject (readonly)

Returns the value of attribute total_word_count.



6
7
8
# File 'lib/groupie/group.rb', line 6

def total_word_count
  @total_word_count
end

#word_countsObject (readonly)

Returns the value of attribute word_counts.



6
7
8
# File 'lib/groupie/group.rb', line 6

def word_counts
  @word_counts
end

Instance Method Details

#add(*words) ⇒ Object Also known as: <<

Add new words to the group.



20
21
22
23
24
25
# File 'lib/groupie/group.rb', line 20

def add(*words)
  words.flatten.each do |word|
    add_word(word)
  end
  nil
end

#count(word) ⇒ Object

Return the count for a specific word.



30
31
32
# File 'lib/groupie/group.rb', line 30

def count(word)
  @word_counts[word] || 0
end

#wordsObject



15
16
17
# File 'lib/groupie/group.rb', line 15

def words
  @word_counts.keys
end