Class: Chronic::Token
- Inherits:
-
Object
- Object
- Chronic::Token
- Defined in:
- lib/chronic/token.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#word ⇒ Object
Returns the value of attribute word.
Instance Method Summary collapse
-
#get_tag(tag_class) ⇒ Object
Return the 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
Return 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.
5 6 7 8 |
# File 'lib/chronic/token.rb', line 5 def initialize(word) @word = word @tags = [] end |
Instance Attribute Details
#tags ⇒ Object
Returns the value of attribute tags.
3 4 5 |
# File 'lib/chronic/token.rb', line 3 def @tags end |
#word ⇒ Object
Returns the value of attribute word.
3 4 5 |
# File 'lib/chronic/token.rb', line 3 def word @word end |
Instance Method Details
#get_tag(tag_class) ⇒ Object
Return the Tag that matches the given class
26 27 28 |
# File 'lib/chronic/token.rb', line 26 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
11 12 13 |
# File 'lib/chronic/token.rb', line 11 def tag(new_tag) @tags << new_tag end |
#tagged? ⇒ Boolean
Return true if this token has any tags
21 22 23 |
# File 'lib/chronic/token.rb', line 21 def tagged? @tags.size > 0 end |
#to_s ⇒ Object
Print this Token in a pretty way
31 32 33 |
# File 'lib/chronic/token.rb', line 31 def to_s @word << '(' << @tags.join(', ') << ') ' end |
#untag(tag_class) ⇒ Object
Remove all tags of the given class
16 17 18 |
# File 'lib/chronic/token.rb', line 16 def untag(tag_class) @tags.delete_if { |m| m.kind_of? tag_class } end |