Class: Temporality::Slice
Instance Attribute Summary collapse
-
#value ⇒ Object
Returns the value of attribute value.
Attributes inherited from TimeSpan
Instance Method Summary collapse
-
#initialize(starts_on, ends_on, value) ⇒ Slice
constructor
A new instance of Slice.
- #intersect(time_span) ⇒ Object
- #to_s ⇒ Object
Methods inherited from TimeSpan
#<=>, #==, #calendaires, #covers?, #day_count, #eql?, #inspect, #intersect!, #intersects?, #ouvrables, #ouvres, #substract
Constructor Details
#initialize(starts_on, ends_on, value) ⇒ Slice
Returns a new instance of Slice.
7 8 9 10 |
# File 'lib/temporality/slice.rb', line 7 def initialize(starts_on, ends_on, value) @value = value super(starts_on, ends_on) end |
Instance Attribute Details
#value ⇒ Object
Returns the value of attribute value.
5 6 7 |
# File 'lib/temporality/slice.rb', line 5 def value @value end |
Instance Method Details
#intersect(time_span) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/temporality/slice.rb', line 16 def intersect(time_span) if time_span.is_a? TimeSpan intersects?(time_span) ? Slice.new([@starts_on, time_span.starts_on].max, [@ends_on, time_span.ends_on].min, @value) : nil elsif time_span.is_a? SliceCollection r = time_span.map { |s| intersect s }.compact r.size > 1 ? SliceCollection.new(s) : s else raise TypeError, 'Argument should be a TimeSpan or a SliceCollection' end end |
#to_s ⇒ Object
12 13 14 |
# File 'lib/temporality/slice.rb', line 12 def to_s "(SL : #{super} -> #{@value})" end |