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.


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

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

Instance Attribute Details

#tagsObject

Returns the value of attribute tags


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

def tags
  @tags
end

#wordObject

Returns the value of attribute word


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

def word
  @word
end

Instance Method Details

#get_tag(tag_class) ⇒ Object

tag_class - The tag Class to search for.

Returns The first Tag that matches the given class.


38
39
40
# File 'lib/chronic/token.rb', line 38

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

#inspectObject


47
48
49
# File 'lib/chronic/token.rb', line 47

def inspect
  to_s
end

#tag(new_tag) ⇒ Object

Tag this token with the specified tag.

new_tag - The new Tag object.

Returns nothing.


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

def tag(new_tag)
  @tags << new_tag if new_tag
end

#tagged?Boolean

Returns true if this token has any tags.

Returns:

  • (Boolean)

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

def tagged?
  @tags.size > 0
end

#to_sObject

Print this Token in a pretty way


43
44
45
# File 'lib/chronic/token.rb', line 43

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

#untag(tag_class) ⇒ Object

Remove all tags of the given class.

tag_class - The tag Class to remove.

Returns nothing.


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

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