Class: Chronic::Separator

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

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, options) ⇒ Array

Scan an Array of Tokens and apply any necessary Separator tags to each token



10
11
12
13
14
15
16
17
18
# File 'lib/chronic/separator.rb', line 10

def self.scan(tokens, options)
  tokens.each do |token|
    if t = scan_for_commas(token) then token.tag(t); next end
    if t = scan_for_slash_or_dash(token) then token.tag(t); next end
    if t = scan_for_at(token) then token.tag(t); next end
    if t = scan_for_in(token) then token.tag(t); next end
    if t = scan_for_on(token) then token.tag(t); next end
  end
end

.scan_for_at(token) ⇒ SeparatorAt?



38
39
40
# File 'lib/chronic/separator.rb', line 38

def self.scan_for_at(token)
  scan_for token, SeparatorAt, { /^(at|@)$/ => :at }
end

.scan_for_commas(token) ⇒ SeparatorComma?



22
23
24
# File 'lib/chronic/separator.rb', line 22

def self.scan_for_commas(token)
  scan_for token, SeparatorComma, { /^,$/ => :comma }
end

.scan_for_in(token) ⇒ SeparatorIn?



44
45
46
# File 'lib/chronic/separator.rb', line 44

def self.scan_for_in(token)
  scan_for token, SeparatorIn, { /^in$/ => :in }
end

.scan_for_on(token) ⇒ SeparatorOn?



50
51
52
# File 'lib/chronic/separator.rb', line 50

def self.scan_for_on(token)
  scan_for token, SeparatorOn, { /^on$/ => :on }
end

.scan_for_slash_or_dash(token) ⇒ SeparatorSlashOrDash?



28
29
30
31
32
33
34
# File 'lib/chronic/separator.rb', line 28

def self.scan_for_slash_or_dash(token)
  scan_for token, SeparatorSlashOrDash,
  {
    /^-$/ => :dash,
    /^\/$/ => :slash
  }
end

Instance Method Details

#to_sObject



54
55
56
# File 'lib/chronic/separator.rb', line 54

def to_s
  'separator'
end