Class: Chronic::Token
- Inherits:
-
Object
- Object
- Chronic::Token
- Defined in:
- lib/chronic/token.rb
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
tag_class - The tag Class to search for.
-
#initialize(word) ⇒ Token
constructor
A new instance of Token.
- #inspect ⇒ Object
-
#tag(new_tag) ⇒ Object
Tag this token with the specified tag.
-
#tagged? ⇒ Boolean
Returns 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.
7 8 9 10 |
# File 'lib/chronic/token.rb', line 7 def initialize(word) @word = word @tags = [] end |
Instance Attribute Details
#tags ⇒ Object
Returns the value of attribute tags.
5 6 7 |
# File 'lib/chronic/token.rb', line 5 def @tags end |
#word ⇒ Object
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 |
#inspect ⇒ Object
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 end |
#tagged? ⇒ Boolean
Returns true if this token has any tags.
31 32 33 |
# File 'lib/chronic/token.rb', line 31 def tagged? @tags.size > 0 end |
#to_s ⇒ Object
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 |