Parent

Files

Chronic::Ordinal

Public Class Methods

scan(tokens, options) click to toggle source

Scan an Array of {Token}s and apply any necessary Ordinal tags to each token

@param [Array<Token>] tokens Array of tokens to scan @param [Hash] options Options specified in {Chronic.parse} @return [Array] list of tokens

# File lib/chronic/ordinal.rb, line 10
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

@param [Token] token @return [OrdinalDay, nil]

# File lib/chronic/ordinal.rb, line 25
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

@param [Token] token @return [Ordinal, nil]

# File lib/chronic/ordinal.rb, line 19
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 33
def to_s
  'ordinal'
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.