File: token.rb

package info (click to toggle)
ruby-chronic 0.10.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 492 kB
  • sloc: ruby: 4,557; makefile: 9; sh: 8
file content (51 lines) | stat: -rw-r--r-- 961 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
module Chronic
  class Token

    attr_accessor :word
    attr_accessor :tags

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

    # Tag this token with the specified tag.
    #
    # new_tag - The new Tag object.
    #
    # Returns nothing.
    def tag(new_tag)
      @tags << new_tag
    end

    # Remove all tags of the given class.
    #
    # tag_class - The tag Class to remove.
    #
    # Returns nothing.
    def untag(tag_class)
      @tags.delete_if { |m| m.kind_of? tag_class }
    end

    # Returns true if this token has any tags.
    def tagged?
      @tags.size > 0
    end

    # tag_class - The tag Class to search for.
    #
    # Returns The first Tag that matches the given class.
    def get_tag(tag_class)
      @tags.find { |m| m.kind_of? tag_class }
    end

    # Print this Token in a pretty way
    def to_s
      @word << '(' << @tags.join(', ') << ') '
    end

    def inspect
      to_s
    end
  end
end