class Chronic::Token

Attributes

tags[RW]

@return [Array] A list of tag associated with this Token

word[RW]

@return [String] The word this Token represents

Public Class Methods

new(word) click to toggle source
# File lib/chronic/token.rb, line 10
def initialize(word)
  @word = word
  @tags = []
end

Public Instance Methods

get_tag(tag_class) click to toggle source

@param [Class] tag_class The tag class to search for @return [Tag] The first Tag that matches the given class

# File lib/chronic/token.rb, line 36
def get_tag(tag_class)
  @tags.find { |m| m.kind_of? tag_class }
end
tag(new_tag) click to toggle source

Tag this token with the specified tag

@param [Tag] new_tag An instance of {Tag} or one of its subclasses

# File lib/chronic/token.rb, line 18
def tag(new_tag)
  @tags << new_tag
end
tagged?() click to toggle source

@return [Boolean] true if this token has any tags

# File lib/chronic/token.rb, line 30
def tagged?
  @tags.size > 0
end
to_s() click to toggle source

Print this Token in a pretty way

# File lib/chronic/token.rb, line 41
def to_s
  @word << '(' << @tags.join(', ') << ') '
end
untag(tag_class) click to toggle source

Remove all tags of the given class

@param [Class] The tag class to remove

# File lib/chronic/token.rb, line 25
def untag(tag_class)
  @tags.delete_if { |m| m.kind_of? tag_class }
end