Sha256: 4aaffccff9086d8d60c81d142f228d6e0d8fccb854744c8a8b465a2318e3446b

Contents?: true

Size: 692 Bytes

Versions: 2

Compression:

Stored size: 692 Bytes

Contents

class ::GridStruct::Selector

  attr_reader :grid, :indexes, :rows, :columns

  def initialize(grid,*indexes)
    @grid = grid
    @indexes = indexes.freeze
  end

  def dimensions(rows,columns)
    @rows = rows
    @columns = columns
    return self
  end

  def [](i)
    mapped_index = @indexes[i]
    mapped_index.nil? ? nil : @grid.store[mapped_index]
  end

  def []=(i,value)
    mapped_index = @indexes[i]
    @grid.store[mapped_index] = value unless mapped_index.nil?
  end

  def to_a
    @indexes.size.times.map do |i|
      self[i]
    end
  end

  def to_grid(rows = nil,columns = nil)
    rows ||= @rows
    columns ||= @columns
    GridStruct.new(rows,columns,to_a)
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
grid_struct-0.1.0 lib/grid_struct/selector.rb
grid_struct-0.0.1 lib/grid_struct/selector.rb