class Overlap::Collection

Attributes

collection[R]

Public Class Methods

new(input_collection, options={}) click to toggle source
# File lib/overlap/collection.rb, line 6
def initialize(input_collection, options={})
  @input_collection = input_collection
  @options = options
  build!
end

Public Instance Methods

to_a() click to toggle source
# File lib/overlap/collection.rb, line 12
def to_a
  collection.map { |e| e.to_a }
end

Private Instance Methods

build!() click to toggle source
# File lib/overlap/collection.rb, line 18
def build!
  _collection = @input_collection.map do |entry|
    _start = entry.send(@options.fetch(:start, :first))
    _end   = entry.send(@options.fetch(:end, :last))
    [ _start, _end ].sort if _start && _end
  end.compact.sort { |x,y| x[0] <=> y[0] }
  @collection = _collection.map { |x, y| Segment.new(x, y) }
end