Class: RRule::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/rrule/generators/generator.rb

Direct Known Subclasses

AllOccurrences, BySetPosition

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ Generator

Returns a new instance of Generator.



7
8
9
# File 'lib/rrule/generators/generator.rb', line 7

def initialize(context)
  @context = context
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



5
6
7
# File 'lib/rrule/generators/generator.rb', line 5

def context
  @context
end

Instance Method Details

#process_timeset(date, timeset) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rrule/generators/generator.rb', line 11

def process_timeset(date, timeset)
  return [date] if timeset.blank?

  timeset.map do |time|
    hour_sets = (
      Array.wrap(time[:hour]).sort.map do |hour|
        Array.wrap(time[:minute]).sort.map do  |minute|
          Array.wrap(time[:second]).sort.map{ |second| [hour, minute, second]}
        end
      end
    ).flatten(2)

    Time.use_zone(context.tz) do
      hour_sets.map do |hour, minute, second|
        Time.zone.local(
          date.year,
          date.month,
          date.day,
          hour,
          minute,
          second
        )
      end
    end
  end.flatten
end