Class: RRule::Rule

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rrule, dtstart: Time.now, tzid: 'UTC', exdate: []) ⇒ Rule

Returns a new instance of Rule.



5
6
7
8
9
10
11
12
13
# File 'lib/rrule/rule.rb', line 5

def initialize(rrule, dtstart: Time.now, tzid: 'UTC', exdate: [])
  @rrule = rrule
  # This removes all sub-second and floors it to the second level.
  # Sub-second level calculations breaks a lot of assumptions in this
  # library and rounding it may also cause unexpected inequalities.
  @dtstart = Time.at(dtstart.to_i).in_time_zone(tzid)
  @tz = tzid
  @exdate = exdate
end

Instance Attribute Details

#dtstartObject (readonly)

Returns the value of attribute dtstart.



3
4
5
# File 'lib/rrule/rule.rb', line 3

def dtstart
  @dtstart
end

#exdateObject (readonly)

Returns the value of attribute exdate.



3
4
5
# File 'lib/rrule/rule.rb', line 3

def exdate
  @exdate
end

#rruleObject (readonly)

Returns the value of attribute rrule.



3
4
5
# File 'lib/rrule/rule.rb', line 3

def rrule
  @rrule
end

#tzObject (readonly)

Returns the value of attribute tz.



3
4
5
# File 'lib/rrule/rule.rb', line 3

def tz
  @tz
end

Instance Method Details

#allObject



15
16
17
# File 'lib/rrule/rule.rb', line 15

def all
  reject_exdates(all_until(nil))
end

#between(start_date, end_date) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/rrule/rule.rb', line 19

def between(start_date, end_date)
  # This removes all sub-second and floors it to the second level.
  # Sub-second level calculations breaks a lot of assumptions in this
  # library and rounding it may also cause unexpected inequalities.
  floored_start_date = Time.at(start_date.to_i)
  floored_end_date = Time.at(end_date.to_i)
  reject_exdates(all_until(floored_end_date).reject { |instance| instance < floored_start_date })
end