Class: Epoch::Pattern
- Inherits:
-
Object
- Object
- Epoch::Pattern
- Defined in:
- lib/epoch/pattern.rb
Constant Summary collapse
- VALID_FREQUENCY =
%w{ daily weekly monthly quarterly semesterly yearly}
Instance Method Summary collapse
- #date_range ⇒ Object
- #dates ⇒ Object
- #end_at ⇒ Object
-
#initialize(frequency, start_at, end_at, interval = 1) ⇒ Pattern
constructor
A new instance of Pattern.
- #start_at ⇒ Object
Constructor Details
#initialize(frequency, start_at, end_at, interval = 1) ⇒ Pattern
Returns a new instance of Pattern.
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/epoch/pattern.rb', line 5 def initialize(frequency, start_at, end_at, interval=1) raise TypeError, 'start_at should be a Date' unless start_at.kind_of?(Date) raise TypeError, 'end_at should be a Date' unless end_at.kind_of?(Date) unless VALID_FREQUENCY.include?(frequency) raise ArgumentError, "frequency should be 'daily', 'weekly', 'monthly', or 'yearly'" end @start_at = start_at @end_at = end_at @frequency = frequency @interval = interval @date_range = start_at..end_at end |
Instance Method Details
#date_range ⇒ Object
25 26 27 |
# File 'lib/epoch/pattern.rb', line 25 def date_range @date_range end |
#dates ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/epoch/pattern.rb', line 29 def dates @dates = [] puts "Find dates between #{@start_at} and #{@end_at}" @date_range.select do |date| case @frequency when "daily" date == date @dates.push date # puts date when "weekly" date.wday == @start_at.wday #@dates.push date # puts date when "monthly" date.mday == @start_at.mday @dates << date # puts date when "yearly" puts "yearly" end end @dates end |
#end_at ⇒ Object
21 22 23 |
# File 'lib/epoch/pattern.rb', line 21 def end_at @end_at end |
#start_at ⇒ Object
17 18 19 |
# File 'lib/epoch/pattern.rb', line 17 def start_at @start_at end |