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) ⇒ Object

Scan an Array of Token objects and apply any necessary Separator tags to each token.

tokens - An Array of tokens to scan. options - The Hash of options specified in Chronic::parse.

Returns an Array of tokens.



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

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) ⇒ Object

token - The Token object we want to scan.

Returns a new SeparatorAt object.



42
43
44
# File 'lib/chronic/separator.rb', line 42

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

.scan_for_commas(token) ⇒ Object

token - The Token object we want to scan.

Returns a new SeparatorComma object.



24
25
26
# File 'lib/chronic/separator.rb', line 24

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

.scan_for_in(token) ⇒ Object

token - The Token object we want to scan.

Returns a new SeparatorIn object.



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

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

.scan_for_on(token) ⇒ Object

token - The Token object we want to scan.

Returns a new SeparatorOn object.



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

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

.scan_for_slash_or_dash(token) ⇒ Object

token - The Token object we want to scan.

Returns a new SeparatorSlashOrDash object.



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

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

Instance Method Details

#to_sObject



60
61
62
# File 'lib/chronic/separator.rb', line 60

def to_s
  'separator'
end