Class: RRule::Rule
Instance Attribute Summary collapse
-
#dtstart ⇒ Object
readonly
Returns the value of attribute dtstart.
-
#exdate ⇒ Object
readonly
Returns the value of attribute exdate.
-
#tz ⇒ Object
readonly
Returns the value of attribute tz.
Instance Method Summary collapse
- #all(limit: nil) ⇒ Object
- #between(start_date, end_date, limit: nil) ⇒ Object
- #each(floor_date: nil) ⇒ Object
- #from(start_date, limit:) ⇒ Object
- #humanize ⇒ Object
-
#initialize(rrule, dtstart: Time.now, tzid: 'UTC', exdate: [], max_year: nil) ⇒ Rule
constructor
A new instance of Rule.
- #is_finite? ⇒ Boolean
- #next ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(rrule, dtstart: Time.now, tzid: 'UTC', exdate: [], max_year: nil) ⇒ Rule
Returns a new instance of Rule.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/rrule/rule.rb', line 9 def initialize(rrule, dtstart: Time.now, tzid: 'UTC', exdate: [], max_year: nil) @tz = tzid @rrule = rrule @dtstart = dtstart.is_a?(Date) ? dtstart : floor_to_seconds_in_timezone(dtstart) @exdate = exdate @options = (rrule) @frequency_type = Frequency.() @max_year = max_year || 9999 @max_date = DateTime.new(@max_year) end |
Instance Attribute Details
#dtstart ⇒ Object (readonly)
Returns the value of attribute dtstart.
7 8 9 |
# File 'lib/rrule/rule.rb', line 7 def dtstart @dtstart end |
#exdate ⇒ Object (readonly)
Returns the value of attribute exdate.
7 8 9 |
# File 'lib/rrule/rule.rb', line 7 def exdate @exdate end |
#tz ⇒ Object (readonly)
Returns the value of attribute tz.
7 8 9 |
# File 'lib/rrule/rule.rb', line 7 def tz @tz end |
Instance Method Details
#all(limit: nil) ⇒ Object
24 25 26 |
# File 'lib/rrule/rule.rb', line 24 def all(limit: nil) all_until(limit: limit) end |
#between(start_date, end_date, limit: nil) ⇒ Object
28 29 30 31 32 |
# File 'lib/rrule/rule.rb', line 28 def between(start_date, end_date, limit: nil) floored_start_date = floor_to_seconds_in_timezone(start_date) floored_end_date = floor_to_seconds_in_timezone(end_date) all_until(start_date: floored_start_date, end_date: floored_end_date, limit: limit).reject { |instance| instance < floored_start_date } end |
#each(floor_date: nil) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/rrule/rule.rb', line 39 def each(floor_date: nil) # If we have a COUNT or INTERVAL option, we have to start at dtstart, because those are relative to dtstart floor_date = dtstart if count_or_interval_present? || floor_date.nil? || dtstart > floor_date return enum_for(:each, floor_date: floor_date) unless block_given? context = Context.new(, dtstart, tz) context.rebuild(floor_date.year, floor_date.month) timeset = [:timeset] count = [:count] filters = [] filters.push(ByMonth.new([:bymonth], context)) if [:bymonth] filters.push(ByWeekNumber.new([:byweekno], context)) if [:byweekno] filters.push(ByWeekDay.new([:byweekday], context)) if [:byweekday] filters.push(ByYearDay.new([:byyearday], context)) if [:byyearday] filters.push(ByMonthDay.new([:bymonthday], context)) if [:bymonthday] generator = if [:bysetpos] BySetPosition.new([:bysetpos], context) else AllOccurrences.new(context) end frequency = Frequency.().new(context, filters, generator, timeset, start_date: floor_date) loop do return if frequency.current_date.year > max_year frequency.next_occurrences.each do |this_result| next if this_result < dtstart next if floor_date.present? && this_result < floor_date return if [:until] && this_result > [:until] return if count && (count -= 1) < 0 yield this_result unless exdate.include?(this_result) end end end |
#from(start_date, limit:) ⇒ Object
34 35 36 37 |
# File 'lib/rrule/rule.rb', line 34 def from(start_date, limit:) floored_start_date = floor_to_seconds_in_timezone(start_date) all_until(start_date: floored_start_date, limit: limit).reject { |instance| instance < floored_start_date } end |
#humanize ⇒ Object
86 87 88 |
# File 'lib/rrule/rule.rb', line 86 def humanize Humanizer.new(self, ).to_s end |
#is_finite? ⇒ Boolean
90 91 92 93 |
# File 'lib/rrule/rule.rb', line 90 def is_finite? keys = %i[count until] & .keys !keys.empty? end |
#next ⇒ Object
82 83 84 |
# File 'lib/rrule/rule.rb', line 82 def next enumerator.next end |
#to_s ⇒ Object
20 21 22 |
# File 'lib/rrule/rule.rb', line 20 def to_s @rrule end |