Sha256: 811d4595e7fe6ce0264938145214a49f2b5601382b5c5bf7bc0f809938de25ef

Contents?: true

Size: 637 Bytes

Versions: 1

Compression:

Stored size: 637 Bytes

Contents

module Overlap
  class Collection

    attr_reader :collection

    def initialize(input_collection, options={})
      @input_collection = input_collection
      @options = options
      build!
    end

    def to_a
      collection.map { |e| e.to_a }
    end

    private

    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
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
overlap-0.2.0 lib/overlap/collection.rb