Class: Chronic::Token
- Inherits:
-
Object
- Object
- Chronic::Token
- Defined in:
- lib/chronic/chronic.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.
157 158 159 160 |
# File 'lib/chronic/chronic.rb', line 157 def initialize(word) @word = word @tags = [] end |
Instance Attribute Details
#tags ⇒ Object
Returns the value of attribute tags.
155 156 157 |
# File 'lib/chronic/chronic.rb', line 155 def @tags end |
#word ⇒ Object
Returns the value of attribute word.
155 156 157 |
# File 'lib/chronic/chronic.rb', line 155 def word @word end |
Instance Method Details
#get_tag(tag_class) ⇒ Object
Return the Tag that matches the given class
178 179 180 181 182 |
# File 'lib/chronic/chronic.rb', line 178 def get_tag(tag_class) matches = @tags.select { |m| m.kind_of? tag_class } #matches.size < 2 || raise("Multiple identical tags found") return matches.first end |
#tag(new_tag) ⇒ Object
Tag this token with the specified tag
163 164 165 |
# File 'lib/chronic/chronic.rb', line 163 def tag(new_tag) @tags << new_tag end |
#tagged? ⇒ Boolean
Return true if this token has any tags
173 174 175 |
# File 'lib/chronic/chronic.rb', line 173 def tagged? @tags.size > 0 end |
#to_s ⇒ Object
Print this Token in a pretty way
185 186 187 |
# File 'lib/chronic/chronic.rb', line 185 def to_s @word << '(' << @tags.join(', ') << ') ' end |
#untag(tag_class) ⇒ Object
Remove all tags of the given class
168 169 170 |
# File 'lib/chronic/chronic.rb', line 168 def untag(tag_class) @tags = @tags.select { |m| !m.kind_of? tag_class } end |