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, text = nil, position = 0) ⇒ Token

Returns a new instance of Token.



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

def initialize(word, text = nil, position = 0)
  @word = word
  @tags = []
  @text = text
  @position = position
end

Instance Attribute Details

#positionObject (readonly)

Returns the value of attribute position.



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

def position
  @position
end

#tagsObject

Returns the value of attribute tags.



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

def tags
  @tags
end

#textObject (readonly)

Returns the value of attribute text.



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

def text
  @text
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

#==(token) ⇒ Object



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

def ==(token)
  token.word == @word.downcase
end

#get_tag(tag_class) ⇒ Object

tag_class - The tag Class to search for.

Returns The first Tag that matches the given class.



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

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

#inspectObject



56
57
58
# File 'lib/chronic/token.rb', line 56

def inspect
  to_s
end

#tag(new_tag) ⇒ Object

Tag this token with the specified tag.

new_tag - The new Tag object.

Returns nothing.



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

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

#tagged?Boolean

Returns true if this token has any tags.

Returns:

  • (Boolean)


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

def tagged?
  @tags.size > 0
end

#to_sObject

Print this Token in a pretty way



52
53
54
# File 'lib/chronic/token.rb', line 52

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.



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

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