Class: Herbalist::Token
- Inherits:
-
Object
- Object
- Herbalist::Token
- Defined in:
- lib/herbalist/herbalist.rb
Overview
based on the Token class found in Chronic
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_type) ⇒ 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_type) ⇒ Object
Remove all tags of the given class.
Constructor Details
#initialize(word) ⇒ Token
Returns a new instance of Token.
68 69 70 71 |
# File 'lib/herbalist/herbalist.rb', line 68 def initialize(word) @word = word @tags = [] end |
Instance Attribute Details
#tags ⇒ Object
Returns the value of attribute tags.
66 67 68 |
# File 'lib/herbalist/herbalist.rb', line 66 def @tags end |
#word ⇒ Object
Returns the value of attribute word.
66 67 68 |
# File 'lib/herbalist/herbalist.rb', line 66 def word @word end |
Instance Method Details
#get_tag(tag_type) ⇒ Object
Return the Tag that matches the given class
89 90 91 92 |
# File 'lib/herbalist/herbalist.rb', line 89 def get_tag(tag_type) matches = @tags.select { |m| m.type==tag_type } return matches.first end |
#tag(new_tag) ⇒ Object
Tag this token with the specified tag
74 75 76 |
# File 'lib/herbalist/herbalist.rb', line 74 def tag(new_tag) @tags << new_tag end |
#tagged? ⇒ Boolean
Return true if this token has any tags
84 85 86 |
# File 'lib/herbalist/herbalist.rb', line 84 def tagged? @tags.size > 0 end |
#to_s ⇒ Object
Print this Token in a pretty way
95 96 97 |
# File 'lib/herbalist/herbalist.rb', line 95 def to_s "#{@word}(#{@tags.join(', ')})" end |
#untag(tag_type) ⇒ Object
Remove all tags of the given class
79 80 81 |
# File 'lib/herbalist/herbalist.rb', line 79 def untag(tag_type) @tags = @tags.select { |m| m.type!=tag_type } end |