Class: Chronic::Scalar
- Inherits:
-
Tag
- Object
- Tag
- Chronic::Scalar
show all
- Defined in:
- lib/chronic/scalar.rb
Overview
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/scalar.rb', line 4
def self.scan(tokens)
tokens.each_index do |i|
if t = self.scan_for_scalars(tokens[i], tokens[i + 1]) then tokens[i].tag(t) end
if t = self.scan_for_days(tokens[i], tokens[i + 1]) then tokens[i].tag(t) end
if t = self.scan_for_months(tokens[i], tokens[i + 1]) then tokens[i].tag(t) end
if t = self.scan_for_years(tokens[i], tokens[i + 1]) then tokens[i].tag(t) end
end
tokens
end
|
.scan_for_days(token, post_token) ⇒ Object
24
25
26
27
28
29
30
31
32
|
# File 'lib/chronic/scalar.rb', line 24
def self.scan_for_days(token, post_token)
if token.word =~ /^\d\d?$/
toi = token.word.to_i
unless toi > 31 || toi < 1 || (post_token && %w{am pm morning afternoon evening night}.include?(post_token.word))
return ScalarDay.new(toi)
end
end
return nil
end
|
.scan_for_months(token, post_token) ⇒ Object
34
35
36
37
38
39
40
41
42
|
# File 'lib/chronic/scalar.rb', line 34
def self.scan_for_months(token, post_token)
if token.word =~ /^\d\d?$/
toi = token.word.to_i
unless toi > 12 || toi < 1 || (post_token && %w{am pm morning afternoon evening night}.include?(post_token.word))
return ScalarMonth.new(toi)
end
end
return nil
end
|
.scan_for_scalars(token, post_token) ⇒ Object
15
16
17
18
19
20
21
22
|
# File 'lib/chronic/scalar.rb', line 15
def self.scan_for_scalars(token, post_token)
if token.word =~ /^\d*$/
unless post_token && %w{am pm morning afternoon evening night}.include?(post_token)
return Scalar.new(token.word.to_i)
end
end
return nil
end
|
.scan_for_years(token, post_token) ⇒ Object
44
45
46
47
48
49
50
51
|
# File 'lib/chronic/scalar.rb', line 44
def self.scan_for_years(token, post_token)
if token.word =~ /^([1-9]\d)?\d\d?$/
unless post_token && %w{am pm morning afternoon evening night}.include?(post_token.word)
return ScalarYear.new(token.word.to_i)
end
end
return nil
end
|
Instance Method Details
#to_s ⇒ Object
53
54
55
|
# File 'lib/chronic/scalar.rb', line 53
def to_s
'scalar'
end
|