Runt

The Runt module is the main namespace for all Runt modules and classes. Using require statements, it makes the entire Runt library available.It also defines some new constants and exposes some already defined in the standard library classes Date and DateTime.

See also runt/sugar_rb which re-opens this module and adds some additional functionality

See also date.rb


Author

Matthew Lipper

Public Class Methods

const(string) click to toggle source
# File lib/runt/sugar.rb, line 149
def const(string)
  self.const_get(string.capitalize)
end
day_name(number) click to toggle source
# File lib/runt.rb, line 62
def day_name(number)
  Date::DAYNAMES[number]
end
format_date(date) click to toggle source
# File lib/runt.rb, line 74
def format_date(date)
  date.ctime
end
format_time(date) click to toggle source
# File lib/runt.rb, line 70
def format_time(date)
  date.strftime('%I:%M%p')
end
month_name(number) click to toggle source
# File lib/runt.rb, line 66
def month_name(number)
  Date::MONTHNAMES[number]
end
ordinalize(number) click to toggle source

Cut and pasted from activesupport-1.2.5/lib/inflector.rb

# File lib/runt.rb, line 81
def ordinalize(number)
  if (number.to_i==-1)
    'last'
  elsif (number.to_i==-2)
    'second to last'  
  elsif (11..13).include?(number.to_i % 100)
    "#{number}th"
  else
    case number.to_i % 10
      when 1 then "#{number}st"
      when 2 then "#{number}nd"
      when 3 then "#{number}rd"
      else    "#{number}th"
    end
  end
end

Public Instance Methods

after(date, inclusive=false) click to toggle source

Shortcut for AfterTE(date, ...).new

# File lib/runt/sugar.rb, line 190
def after(date, inclusive=false)
  AfterTE.new(date, inclusive)
end
before(date, inclusive=false) click to toggle source

Shortcut for BeforeTE(date, ...).new

# File lib/runt/sugar.rb, line 195
def before(date, inclusive=false)
  BeforeTE.new(date, inclusive)
end
method_missing(name, *args, &block) click to toggle source
# File lib/runt/sugar.rb, line 154
def method_missing(name, *args, &block) 
      #puts "method_missing(#{name},#{args},#{block}) => #{result}"
  case name.to_s
  when /^daily_(\d{1,2})_(\d{2})([ap]m)_to_(\d{1,2})_(\d{2})([ap]m)$/
    # REDay
    st_hr, st_min, st_m, end_hr, end_min, end_m = $1, $2, $3, $4, $5, $6
    args = parse_time(st_hr, st_min, st_m)
    args.concat(parse_time(end_hr, end_min, end_m))
    return REDay.new(*args)
  when Regexp.new('^weekly_' + DAYS + '_to_' + DAYS + '$')
    # REWeek
    st_day, end_day = $1, $2
    return REWeek.new(Runt.const(st_day), Runt.const(end_day))
  when Regexp.new('^monthly_(\d{1,2})' + ORDINAL_SUFFIX + '_to_(\d{1,2})'                      + ORDINAL_SUFFIX + '$')
    # REMonth
    st_day, end_day = $1, $2
    return REMonth.new(st_day, end_day)
  when Regexp.new('^yearly_' + MONTHS + '_(\d{1,2})_to_' + MONTHS + '_(\d{1,2})$')
    # REYear
    st_mon, st_day, end_mon, end_day = $1, $2, $3, $4
    return REYear.new(Runt.const(st_mon), st_day, Runt.const(end_mon), end_day)
  when Regexp.new('^' + DAYS + '$')
    # DIWeek
    return DIWeek.new(Runt.const(name.to_s))
  when Regexp.new(WEEK_OF_MONTH_ORDINALS + '_' + DAYS)
    # DIMonth
    ordinal, day = $1, $2
    return DIMonth.new(Runt.const(ordinal), Runt.const(day))
  else
    # You're hosed
        super
  end
end
parse_time(hour, minute, ampm) click to toggle source
# File lib/runt/sugar.rb, line 199
def parse_time(hour, minute, ampm)
  hour = hour.to_i + 12 if ampm =~ /pm/
  [hour.to_i, minute.to_i]
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.