File: tag.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 (37 lines) | stat: -rw-r--r-- 774 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
module Chronic
  # Tokens are tagged with subclassed instances of this class when
  # they match specific criteria.
  class Tag

    attr_accessor :type

    # type - The Symbol type of this tag.
    def initialize(type, options = {})
      @type = type
      @options = options
    end

    # time - Set the start Time for this Tag.
    def start=(time)
      @now = time
    end

    class << self
      private

      def scan_for(token, klass, items={}, options = {})
        case items
        when Regexp
          return klass.new(token.word, options) if items =~ token.word
        when Hash
          items.each do |item, symbol|
            return klass.new(symbol, options) if item =~ token.word
          end
        end
        nil
      end

    end

  end
end