Module Runt
In: lib/runt/pdate.rb
lib/runt/dprecision.rb
lib/runt/temporalexpression.rb
lib/runt/daterange.rb
lib/runt/schedule.rb
lib/runt/sugar.rb
lib/runt.rb

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

Methods

Classes and Modules

Module Runt::DPrecision
Module Runt::TExpr
Module Runt::TExprUtils
Class Runt::AfterTE
Class Runt::BeforeTE
Class Runt::Collection
Class Runt::DIMonth
Class Runt::DIWeek
Class Runt::DateRange
Class Runt::DayIntervalTE
Class Runt::Diff
Class Runt::Event
Class Runt::EveryTE
Class Runt::Intersect
Class Runt::PDate
Class Runt::REDay
Class Runt::REMonth
Class Runt::REWeek
Class Runt::REYear
Class Runt::RSpec
Class Runt::Schedule
Class Runt::Spec
Class Runt::Union
Class Runt::WIMonth
Class Runt::YearTE

Constants

MONTHS = '(january|february|march|april|may|june|july|august|september|october|november|december)'
DAYS = '(sunday|monday|tuesday|wednesday|thursday|friday|saturday)'
WEEK_OF_MONTH_ORDINALS = '(first|second|third|fourth|last|second_to_last)'
ORDINAL_SUFFIX = '(?:st|nd|rd|th)'
ORDINAL_ABBR = '(st|nd|rd|th)'
Sunday = Date::DAYNAMES.index("Sunday")   Yes it‘s true, I‘m a big idiot!
Monday = Date::DAYNAMES.index("Monday")
Tuesday = Date::DAYNAMES.index("Tuesday")
Wednesday = Date::DAYNAMES.index("Wednesday")
Thursday = Date::DAYNAMES.index("Thursday")
Friday = Date::DAYNAMES.index("Friday")
Saturday = Date::DAYNAMES.index("Saturday")
Sun = Date::ABBR_DAYNAMES.index("Sun")
Mon = Date::ABBR_DAYNAMES.index("Mon")
Tue = Date::ABBR_DAYNAMES.index("Tue")
Wed = Date::ABBR_DAYNAMES.index("Wed")
Thu = Date::ABBR_DAYNAMES.index("Thu")
Fri = Date::ABBR_DAYNAMES.index("Fri")
Sat = Date::ABBR_DAYNAMES.index("Sat")
January = Date::MONTHNAMES.index("January")
February = Date::MONTHNAMES.index("February")
March = Date::MONTHNAMES.index("March")
April = Date::MONTHNAMES.index("April")
May = Date::MONTHNAMES.index("May")
June = Date::MONTHNAMES.index("June")
July = Date::MONTHNAMES.index("July")
August = Date::MONTHNAMES.index("August")
September = Date::MONTHNAMES.index("September")
October = Date::MONTHNAMES.index("October")
November = Date::MONTHNAMES.index("November")
December = Date::MONTHNAMES.index("December")
First = 1
Second = 2
Third = 3
Fourth = 4
Fifth = 5
Sixth = 6
Seventh = 7
Eighth = 8
Eigth = 8
Ninth = 9
Tenth = 10
LastProc = ApplyLast.new
Last = LastProc[First]
Last_of = LastProc[First]
Second_to_last = LastProc[Second]

Public Class methods

[Source]

# File lib/runt/sugar.rb, line 122
    def const(string)
      self.const_get(string.capitalize)
    end

[Source]

# File lib/runt.rb, line 60
    def day_name(number)
      Date::DAYNAMES[number]
    end

[Source]

# File lib/runt.rb, line 72
    def format_date(date)
      date.ctime
    end

[Source]

# File lib/runt.rb, line 68
    def format_time(date)
      date.strftime('%I:%M%p')
    end

[Source]

# File lib/runt.rb, line 64
    def month_name(number)
      Date::MONTHNAMES[number]
    end

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

[Source]

# File lib/runt.rb, line 79
    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: "#{number}st"
          when 2: "#{number}nd"
          when 3: "#{number}rd"
          else    "#{number}th"
        end
      end
    end

Public Instance methods

[Source]

# File lib/runt/sugar.rb, line 133
  def build(name, *args, &block)
    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
      nil
    end
  end

[Source]

# File lib/runt/sugar.rb, line 127
  def method_missing(name, *args, &block) 
    result = self.build(name, *args, &block)
    return result unless result.nil?
    super
  end

[Source]

# File lib/runt/sugar.rb, line 167
  def parse_time(hour, minute, ampm)
    hour = hour.to_i + 12 if ampm =~ /pm/
    [hour.to_i, minute.to_i]
  end

[Validate]