Class: Chronic::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/chronic/token.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(word) ⇒ Token

Returns a new instance of Token.



10
11
12
13
# File 'lib/chronic/token.rb', line 10

def initialize(word)
  @word = word
  @tags = []
end

Instance Attribute Details

#tagsArray

Returns A list of tag associated with this Token.

Returns:

  • (Array)

    A list of tag associated with this Token



8
9
10
# File 'lib/chronic/token.rb', line 8

def tags
  @tags
end

#wordString

Returns The word this Token represents.

Returns:

  • (String)

    The word this Token represents



5
6
7
# File 'lib/chronic/token.rb', line 5

def word
  @word
end

Instance Method Details

#get_tag(tag_class) ⇒ Tag

Returns The first Tag that matches the given class.

Parameters:

  • tag_class (Class)

    The tag class to search for

Returns:

  • (Tag)

    The first Tag that matches the given class



36
37
38
# File 'lib/chronic/token.rb', line 36

def get_tag(tag_class)
  @tags.find { |m| m.kind_of? tag_class }
end

#tag(new_tag) ⇒ Object

Tag this token with the specified tag

Parameters:



18
19
20
# File 'lib/chronic/token.rb', line 18

def tag(new_tag)
  @tags << new_tag
end

#tagged?Boolean

Returns true if this token has any tags.

Returns:

  • (Boolean)

    true if this token has any tags



30
31
32
# File 'lib/chronic/token.rb', line 30

def tagged?
  @tags.size > 0
end

#to_sObject

Print this Token in a pretty way



41
42
43
# File 'lib/chronic/token.rb', line 41

def to_s
  @word << '(' << @tags.join(', ') << ') '
end

#untag(tag_class) ⇒ Object

Remove all tags of the given class

Parameters:

  • The (Class)

    tag class to remove



25
26
27
# File 'lib/chronic/token.rb', line 25

def untag(tag_class)
  @tags.delete_if { |m| m.kind_of? tag_class }
end