Class: Agenda::Word

Inherits:
Object
  • Object
show all
Defined in:
lib/agenda/word.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(the_word) ⇒ Word

Returns a new instance of Word.



5
6
7
# File 'lib/agenda/word.rb', line 5

def initialize(the_word)
  @word = the_word.downcase; @count = 0; @tags = []
end

Instance Attribute Details

#countObject

Returns the value of attribute count.



3
4
5
# File 'lib/agenda/word.rb', line 3

def count
  @count
end

#tagsObject

Returns the value of attribute tags.



3
4
5
# File 'lib/agenda/word.rb', line 3

def tags
  @tags
end

#wordObject

Returns the value of attribute word.



3
4
5
# File 'lib/agenda/word.rb', line 3

def word
  @word
end

Instance Method Details

#==(other) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/agenda/word.rb', line 23

def ==(other)
  if other.is_a? Agenda::Word
    return other.word == @word
  else other.is_a? String
    return other == @word
  end
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/agenda/word.rb', line 19

def eql?(other)
  other.word == @word
end

#has_tag?(tag) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/agenda/word.rb', line 15

def has_tag?(tag)
  @tags.include? tag
end

#to_sObject



9
10
11
12
13
# File 'lib/agenda/word.rb', line 9

def to_s
  s = "#{@word}: #{@count}"
  s += " (" + @tags.join(", ") + ")" unless @tags.empty?
  s
end