Class: Temporality::Slice

Inherits:
TimeSpan show all
Defined in:
lib/temporality/slice.rb

Instance Attribute Summary collapse

Attributes inherited from TimeSpan

#ends_on, #starts_on

Instance Method Summary collapse

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

#valueObject

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_sObject



12
13
14
# File 'lib/temporality/slice.rb', line 12

def to_s
  "(SL : #{super} -> #{@value})"
end