class Temporality::TimeSpanCollection
Public Class Methods
new(collection = [])
click to toggle source
Calls superclass method
# File lib/temporality/time_span_collection.rb, line 5 def initialize(collection = []) super() collection = [collection].flatten # Support pour ne passer qu'un seul TS collection.map { |ts| self << (ts.is_a?(TimeSpan) ? ts : raise(TypeError, "Element is not a Temporality::TimeSpan")) } sort! end
Public Instance Methods
inspect()
click to toggle source
# File lib/temporality/time_span_collection.rb, line 16 def inspect to_s end
intersect(tsc)
click to toggle source
# File lib/temporality/time_span_collection.rb, line 39 def intersect(tsc) res = tsc.inject(TimeSpanCollection.new) do |r, ts| r << ts.intersect(self) end.compact.sort TimeSpanCollection.new(res) end
intersect!(time_span)
click to toggle source
# File lib/temporality/time_span_collection.rb, line 27 def intersect!(time_span) if time_span.is_a? TimeSpan map! { |ts| ts.intersect(time_span) }.compact! elsif time_span.is_a? TimeSpanCollection raise 'Not handling time_span collections yet' else raise TypeError, "Element is not a Temporality::TimeSpan or a Temporality::TimeSpanCollection" end self end
intersects?(time_span)
click to toggle source
# File lib/temporality/time_span_collection.rb, line 47 def intersects?(time_span) any? { |ts| ts.intersects? time_span } end
limit_to!(time_span)
click to toggle source
# File lib/temporality/time_span_collection.rb, line 20 def limit_to!(time_span) reject! { |ts| !ts.intersects?(time_span) } first.starts_on = [first.starts_on, time_span.starts_on].max last.ends_on = [last.ends_on, time_span.ends_on].min self end
substract(time_span)
click to toggle source
# File lib/temporality/time_span_collection.rb, line 51 def substract(time_span) raise TypeError, "Not a TimeSpan" unless time_span.is_a? TimeSpan TimeSpanCollection.new( map do |ts| ts.substract(time_span) end ) end
to_s()
click to toggle source
# File lib/temporality/time_span_collection.rb, line 12 def to_s "{TSC : #{map { |ts| ts.to_s }.join(", ")}}" end