Class: Chronic::Token
- Inherits:
-
Object
- Object
- Chronic::Token
- Defined in:
- lib/chronic/token.rb
Instance Attribute Summary collapse
-
#tags ⇒ Array
A list of tag associated with this Token.
-
#word ⇒ String
The word this Token represents.
Instance Method Summary collapse
-
#get_tag(tag_class) ⇒ Tag
The first Tag that matches the given class.
-
#initialize(word) ⇒ Token
constructor
A new instance of Token.
-
#tag(new_tag) ⇒ Object
Tag this token with the specified tag.
-
#tagged? ⇒ Boolean
True if this token has any tags.
-
#to_s ⇒ Object
Print this Token in a pretty way.
-
#untag(tag_class) ⇒ Object
Remove all tags of the given class.
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
#tags ⇒ Array
Returns A list of tag associated with this Token.
8 9 10 |
# File 'lib/chronic/token.rb', line 8 def @tags end |
#word ⇒ String
Returns 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.
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
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.
30 31 32 |
# File 'lib/chronic/token.rb', line 30 def tagged? @tags.size > 0 end |
#to_s ⇒ Object
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
25 26 27 |
# File 'lib/chronic/token.rb', line 25 def untag(tag_class) @tags.delete_if { |m| m.kind_of? tag_class } end |