class Chronic::Ordinal

Public Class Methods

scan(tokens, options) click to toggle source

Scan an Array of Token objects and apply any necessary Ordinal 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.

# File lib/chronic/ordinal.rb, line 11
def self.scan(tokens, options)
  tokens.each do |token|
    if t = scan_for_ordinals(token) then token.tag(t) end
    if t = scan_for_days(token) then token.tag(t) end
  end
end
scan_for_days(token) click to toggle source

token - The Token object we want to scan.

Returns a new Ordinal object.

# File lib/chronic/ordinal.rb, line 28
def self.scan_for_days(token)
  if token.word =~ /^(\d*)(st|nd|rd|th)$/
    unless $1.to_i > 31 || $1.to_i < 1
      OrdinalDay.new(token.word.to_i)
    end
  end
end
scan_for_ordinals(token) click to toggle source

token - The Token object we want to scan.

Returns a new Ordinal object.

# File lib/chronic/ordinal.rb, line 21
def self.scan_for_ordinals(token)
  Ordinal.new($1.to_i) if token.word =~ /^(\d*)(st|nd|rd|th)$/
end

Public Instance Methods

to_s() click to toggle source
# File lib/chronic/ordinal.rb, line 36
def to_s
  'ordinal'
end