module 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
Constants
- April
- August
- DAYS
- December
- Eighth
- Eigth
- February
- Fifth
- First
- Fourth
- Fri
- Friday
- January
- July
- June
- Last
- LastProc
- Last_of
- MONTHS
- March
- May
- Mon
- Monday
- Ninth
- November
- ORDINAL_ABBR
- ORDINAL_SUFFIX
- October
- Sat
- Saturday
- Second
- Second_to_last
- September
- Seventh
- Sixth
- Sun
- Sunday
-
Yes it’s true, I’m a big idiot!
- Tenth
- Third
- Thu
- Thursday
- Tue
- Tuesday
- WEEK_OF_MONTH_ORDINALS
- Wed
- Wednesday
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 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
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
Cut and pasted from activesupport-1.2.5/lib/inflector.rb
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
Calls superclass method
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