Class: Chronic::Token

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

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(word) ⇒ Token

Returns a new instance of Token.



251
252
253
254
# File 'lib/chronic/chronic.rb', line 251

def initialize(word)
  @word = word
  @tags = []
end

Instance Attribute Details

#tagsObject

Returns the value of attribute tags.



249
250
251
# File 'lib/chronic/chronic.rb', line 249

def tags
  @tags
end

#wordObject

Returns the value of attribute word.



249
250
251
# File 'lib/chronic/chronic.rb', line 249

def word
  @word
end

Instance Method Details

#get_tag(tag_class) ⇒ Object

Return the Tag that matches the given class



272
273
274
275
276
# File 'lib/chronic/chronic.rb', line 272

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



257
258
259
# File 'lib/chronic/chronic.rb', line 257

def tag(new_tag)
  @tags << new_tag
end

#tagged?Boolean

Return true if this token has any tags

Returns:

  • (Boolean)


267
268
269
# File 'lib/chronic/chronic.rb', line 267

def tagged?
  @tags.size > 0
end

#to_sObject

Print this Token in a pretty way



279
280
281
# File 'lib/chronic/chronic.rb', line 279

def to_s
  @word << '(' << @tags.join(', ') << ') '
end

#untag(tag_class) ⇒ Object

Remove all tags of the given class



262
263
264
# File 'lib/chronic/chronic.rb', line 262

def untag(tag_class)
  @tags = @tags.select { |m| !m.kind_of? tag_class }
end