Sha256: 7dfda173659eaec7a3a791e598e0c27346b2c09ebf4fe997413ab401d6b013b8

Contents?: true

Size: 601 Bytes

Versions: 1

Compression:

Stored size: 601 Bytes

Contents

module Qi
  class Store
    attr_reader :size, :captured, :position

    def initialize(size, captured = nil, position = {})
      @size     = Integer(size)
      @captured = captured
      @position = Hash(position.compact)

      freeze
    end

    def call(position_id, capture_position_id, content)
      self.class.new(
        size,
        position[capture_position_id],
        position.merge(
          Integer(position_id)          => nil,
          Integer(capture_position_id)  => content
        )
      )
    end

    def to_a
      (0...size).map { |i| position[i] }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
qi-5.0.0 lib/qi/store.rb