Class: Cyclical::Suboccurrence
- Inherits:
-
Object
- Object
- Cyclical::Suboccurrence
- Defined in:
- lib/cyclical/suboccurrence.rb
Overview
Holds suboccurrence of a schedule, i.e. time interval which is a subinterval of a single occurrence. This is used to find actual time spans to display in a given time interval (for example in a calendar)
Instance Attribute Summary collapse
-
#end ⇒ Object
readonly
Returns the value of attribute end.
-
#occurrence_end ⇒ Object
(also: #occurrence_end?)
readonly
Returns the value of attribute occurrence_end.
-
#occurrence_start ⇒ Object
(also: #occurrence_start?)
readonly
Returns the value of attribute occurrence_start.
-
#start ⇒ Object
readonly
Returns the value of attribute start.
Class Method Summary collapse
-
.find(attrs) ⇒ Object
factory method for finding suboccurrence of a single occurrence with an interval, with the ability to return nil This might be a totally bad idea, I’m not sure right now really…
Instance Attribute Details
#end ⇒ Object (readonly)
Returns the value of attribute end.
5 6 7 |
# File 'lib/cyclical/suboccurrence.rb', line 5 def end @end end |
#occurrence_end ⇒ Object (readonly) Also known as: occurrence_end?
Returns the value of attribute occurrence_end.
5 6 7 |
# File 'lib/cyclical/suboccurrence.rb', line 5 def occurrence_end @occurrence_end end |
#occurrence_start ⇒ Object (readonly) Also known as: occurrence_start?
Returns the value of attribute occurrence_start.
5 6 7 |
# File 'lib/cyclical/suboccurrence.rb', line 5 def occurrence_start @occurrence_start end |
#start ⇒ Object (readonly)
Returns the value of attribute start.
5 6 7 |
# File 'lib/cyclical/suboccurrence.rb', line 5 def start @start end |
Class Method Details
.find(attrs) ⇒ Object
factory method for finding suboccurrence of a single occurrence with an interval, with the ability to return nil This might be a totally bad idea, I’m not sure right now really…
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 37 |
# File 'lib/cyclical/suboccurrence.rb', line 12 def self.find(attrs) raise ArgumentError, "Missing occurrence" unless (occurrence = attrs[:occurrence]).is_a?(Range) raise ArgumentError, "Missing interval" unless (interval = attrs[:interval]).is_a?(Range) return nil if occurrence.last <= interval.first || occurrence.first >= interval.last suboccurrence = {} if occurrence.first < interval.first suboccurrence[:start] = interval.first suboccurrence[:occurrence_start] = false else suboccurrence[:start] = occurrence.first suboccurrence[:occurrence_start] = true end if occurrence.last > interval.last suboccurrence[:end] = interval.last suboccurrence[:occurrence_end] = false else suboccurrence[:end] = occurrence.last suboccurrence[:occurrence_end] = true end return new(suboccurrence) end |