module DateFinderConditions def day_number(day_number) condition(:day_number) { |date| date.day == day_number } end def day(day) day = case day when Fixnum day when String, Symbol Date::Format::DAYS[day.to_s.downcase] end condition(:day) { |date| date.wday == day } end Date::Format::DAYS.each do |name, index| class_eval <<-END def #{name}(boolean) day(#{index}) if boolean end END end def weekday condition(:weekday) { |date| date.weekday? } end def month(month) month = case month when Fixnum: month when String, Symbol: Date::Format::MONTHS[month.to_s.downcase] end condition(:month) { |date| date.month == month } end def day_occurrence(occurrence) condition(:day_occurrence) { |date| date.occurrence_in_month?(occurrence) } end def method_missing(method_id, *args) method_name = method_id.to_s singular = method_name.singularize if singular != method_name and respond_to?(singular) args.each { |arg| send(singular, arg) } self else super end end end