Class: RRule::Frequency
- Inherits:
-
Object
- Object
- RRule::Frequency
- Defined in:
- lib/rrule/frequencies/frequency.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#current_date ⇒ Object
readonly
Returns the value of attribute current_date.
-
#filters ⇒ Object
readonly
Returns the value of attribute filters.
-
#generator ⇒ Object
readonly
Returns the value of attribute generator.
-
#timeset ⇒ Object
readonly
Returns the value of attribute timeset.
Class Method Summary collapse
Instance Method Summary collapse
- #advance ⇒ Object
-
#initialize(context, filters, generator, timeset, start_date: nil) ⇒ Frequency
constructor
A new instance of Frequency.
- #next_occurrences ⇒ Object
Constructor Details
#initialize(context, filters, generator, timeset, start_date: nil) ⇒ Frequency
Returns a new instance of Frequency.
7 8 9 10 11 12 13 |
# File 'lib/rrule/frequencies/frequency.rb', line 7 def initialize(context, filters, generator, timeset, start_date: nil) @context = context @current_date = start_date.presence || context.dtstart @filters = filters @generator = generator @timeset = timeset end |
Instance Attribute Details
#current_date ⇒ Object (readonly)
Returns the value of attribute current_date.
5 6 7 |
# File 'lib/rrule/frequencies/frequency.rb', line 5 def current_date @current_date end |
#filters ⇒ Object (readonly)
Returns the value of attribute filters.
5 6 7 |
# File 'lib/rrule/frequencies/frequency.rb', line 5 def filters @filters end |
#generator ⇒ Object (readonly)
Returns the value of attribute generator.
5 6 7 |
# File 'lib/rrule/frequencies/frequency.rb', line 5 def generator @generator end |
#timeset ⇒ Object (readonly)
Returns the value of attribute timeset.
5 6 7 |
# File 'lib/rrule/frequencies/frequency.rb', line 5 def timeset @timeset end |
Class Method Details
.for_options(options) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/rrule/frequencies/frequency.rb', line 35 def self.() case [:freq] when 'DAILY' Daily when 'WEEKLY' if [:simple_weekly] && ![:bymonth] SimpleWeekly # simplified and faster version if we don't need to deal with filtering else Weekly end when 'MONTHLY' Monthly when 'YEARLY' Yearly else raise InvalidRRule, 'Valid FREQ value is required' end end |
Instance Method Details
#advance ⇒ Object
15 16 17 18 19 |
# File 'lib/rrule/frequencies/frequency.rb', line 15 def advance @current_date = current_date.advance(advance_by).tap do |new_date| context.rebuild(new_date.year, new_date.month) unless same_month(current_date, new_date) end end |
#next_occurrences ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rrule/frequencies/frequency.rb', line 21 def next_occurrences possible_days_of_year = possible_days if filters.present? possible_days_of_year.each_with_index do |day_index, i| possible_days_of_year[i] = nil if filters.any? { |filter| filter.reject?(day_index) } end end generator.combine_dates_and_times(possible_days_of_year, timeset).tap do advance end end |