class Overlap::Union
Attributes
intersection_quantity[R]
intersections[R]
quantity[R]
quantity_with_intersections[R]
segment[R]
segments[R]
Public Class Methods
new(overlapped_segments)
click to toggle source
# File lib/overlap/union.rb, line 6 def initialize(overlapped_segments) @overlapped_segments = overlapped_segments @segments = overlapped_segments[:segments].sort build! end
Private Instance Methods
build!()
click to toggle source
# File lib/overlap/union.rb, line 14 def build! @segment = @overlapped_segments[:union] @quantity = segment.quantity previous_value = nil @intersections = segments.sort.map do |_segment| intersection = nil if previous_value intersection = previous_value - _segment.start_position end previous_value = _segment.end_position intersection end.compact @intersection_quantity = intersections.reduce(:+)&.round(3) || 0 @quantity_with_intersections = segments.map(&:quantity).reduce(:+)&.round(3) || 0 end