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 |
Yes it's true, I'm a big idiot!
# File lib/runt/sugar.rb, line 149 def const(string) self.const_get(string.capitalize) end
# File lib/runt.rb, line 62 def day_name(number) Date::DAYNAMES[number] end
# File lib/runt.rb, line 74 def format_date(date) date.ctime end
# File lib/runt.rb, line 70 def format_time(date) date.strftime('%I:%M%p') end
# File lib/runt.rb, line 66 def month_name(number) Date::MONTHNAMES[number] end
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
Shortcut for AfterTE(date, ...).new
# File lib/runt/sugar.rb, line 190 def after(date, inclusive=false) AfterTE.new(date, inclusive) end
Shortcut for BeforeTE(date, ...).new
# File lib/runt/sugar.rb, line 195 def before(date, inclusive=false) BeforeTE.new(date, inclusive) end
# 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
Generated with the Darkfish Rdoc Generator 2.