Class: Herbalist::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/herbalist/herbalist.rb

Overview

based on the Token class found in Chronic

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#tagsObject

Returns the value of attribute tags.



66
67
68
# File 'lib/herbalist/herbalist.rb', line 66

def tags
  @tags
end

#wordObject

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

Returns:

  • (Boolean)


84
85
86
# File 'lib/herbalist/herbalist.rb', line 84

def tagged?
  @tags.size > 0
end

#to_sObject

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