Class: Chronic::Separator

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

Overview

:nodoc:

Instance Attribute Summary

Attributes inherited from Tag

#type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Tag

#initialize, #start=

Constructor Details

This class inherits a constructor from Chronic::Tag

Class Method Details

.scan(tokens) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/chronic/separator.rb', line 4

def self.scan(tokens)
  tokens.each_index do |i|
    if t = self.scan_for_commas(tokens[i]) then tokens[i].tag(t); next end
    if t = self.scan_for_slash_or_dash(tokens[i]) then tokens[i].tag(t); next end
    if t = self.scan_for_at(tokens[i]) then tokens[i].tag(t); next end
    if t = self.scan_for_in(tokens[i]) then tokens[i].tag(t); next end
    if t = self.scan_for_on(tokens[i]) then tokens[i].tag(t); next end
  end
  tokens
end

.scan_for_at(token) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/chronic/separator.rb', line 32

def self.scan_for_at(token)
  scanner = {/^(at|@)$/ => :at}
  scanner.keys.each do |scanner_item|
    return SeparatorAt.new(scanner[scanner_item]) if scanner_item =~ token.word
  end
  return nil
end

.scan_for_commas(token) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/chronic/separator.rb', line 15

def self.scan_for_commas(token)
  scanner = {/^,$/ => :comma}
  scanner.keys.each do |scanner_item|
    return SeparatorComma.new(scanner[scanner_item]) if scanner_item =~ token.word
  end
  return nil
end

.scan_for_in(token) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/chronic/separator.rb', line 40

def self.scan_for_in(token)
  scanner = {/^in$/ => :in}
  scanner.keys.each do |scanner_item|
    return SeparatorIn.new(scanner[scanner_item]) if scanner_item =~ token.word
  end
  return nil
end

.scan_for_on(token) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/chronic/separator.rb', line 48

def self.scan_for_on(token)
  scanner = {/^on$/ => :on}
  scanner.keys.each do |scanner_item|
    return SeparatorOn.new(scanner[scanner_item]) if scanner_item =~ token.word
  end
  return nil
end

.scan_for_slash_or_dash(token) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/chronic/separator.rb', line 23

def self.scan_for_slash_or_dash(token)
  scanner = {/^-$/ => :dash,
             /^\/$/ => :slash}
  scanner.keys.each do |scanner_item|
    return SeparatorSlashOrDash.new(scanner[scanner_item]) if scanner_item =~ token.word
  end
  return nil
end

Instance Method Details

#to_sObject



56
57
58
# File 'lib/chronic/separator.rb', line 56

def to_s
  'separator'
end