class PictureFrame::Canvas

Public Class Methods

new(*dimensions) click to toggle source
Calls superclass method
# File lib/picture_frame/canvas.rb, line 5
def initialize(*dimensions)
  rows, cols = 0, 0
  dimensions.each do |r, c|
    rows += r
    cols += c
  end

  raster = (1..rows).inject([]) { |r| r << ' ' * cols }
  super(raster)
end

Public Instance Methods

print_at(pos, raster, start = nil, length = nil) click to toggle source

Private Instance Methods

make_range(start, length) click to toggle source
# File lib/picture_frame/canvas.rb, line 64
def make_range(start, length)
  start..(start + length - 1)
end
overwrite(row_pos, col_pos, raster) click to toggle source
# File lib/picture_frame/canvas.rb, line 43
def overwrite(row_pos, col_pos, raster)
  if row_pos.is_a?(Range)
    row_pos.each do |r|
      overwrite(r, col_pos, raster)
    end
  elsif col_pos.is_a?(Range)
    col_pos.each do |c|
      overwrite(row_pos, c, raster)
    end
  else
    overwrite1(row_pos, col_pos, raster)
  end
end
overwrite1(row_pos, col_pos, raster) click to toggle source
# File lib/picture_frame/canvas.rb, line 57
def overwrite1(row_pos, col_pos, raster)
  cols = raster.width
  raster.each_with_index do |row, r|
    @raster[row_pos + r][col_pos, cols] = row
  end
end