Class: Chronic::Ordinal
- Inherits:
-
Tag
- Object
- Tag
- Chronic::Ordinal
show all
- Defined in:
- lib/chronic/ordinal.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
|
# File 'lib/chronic/ordinal.rb', line 4
def self.scan(tokens)
tokens.each_index do |i|
if t = self.scan_for_ordinals(tokens[i]) then tokens[i].tag(t) end
if t = self.scan_for_days(tokens[i]) then tokens[i].tag(t) end
end
tokens
end
|
.scan_for_days(token) ⇒ Object
20
21
22
23
24
25
26
27
|
# File 'lib/chronic/ordinal.rb', line 20
def self.scan_for_days(token)
if token.word =~ /^(\d*)(st|nd|rd|th)$/
unless $1.to_i > 31 || $1.to_i < 1
return OrdinalDay.new(token.word.to_i)
end
end
return nil
end
|
.scan_for_ordinals(token) ⇒ Object
13
14
15
16
17
18
|
# File 'lib/chronic/ordinal.rb', line 13
def self.scan_for_ordinals(token)
if token.word =~ /^(\d*)(st|nd|rd|th)$/
return Ordinal.new($1.to_i)
end
return nil
end
|
Instance Method Details
#to_s ⇒ Object
29
30
31
|
# File 'lib/chronic/ordinal.rb', line 29
def to_s
'ordinal'
end
|