class PictureFrame::Stencil

Public Class Methods

new(*) click to toggle source
Calls superclass method PictureFrame::Raster::new
# File lib/picture_frame/stencil.rb, line 5
def initialize(*)
  super
end

Public Instance Methods

position(char) click to toggle source
# File lib/picture_frame/stencil.rb, line 9
def position(char)
  @raster.each_with_index do |row, ri|
    row.chars.each_with_index do |cell, ci|
      return ri, ci if cell == char
    end
  end
  []
end
slice_from(pos, to) click to toggle source
# File lib/picture_frame/stencil.rb, line 18
def slice_from(pos, to)
  r, c = pos
  n, m = bottom_right

  case to
  when :t, :top
    slice([0, c], [r - 1, c])
  when :r, :right
    slice([r, c + 1], [r, m])
  when :b, :bottom
    slice([r + 1, c], [n, c])
  when :l, :left
    slice([r, 0], [r, c - 1])

  when :tl, :top_left
    slice([0, 0], [r - 1, c - 1])
  when :tr, :top_right
    slice([0, c + 1], [r - 1, m])
  when :br, :bottom_right
    slice([r + 1, c + 1], [n, m])
  when :bl, :bottom_left
    slice([r + 1, 0], [n, c - 1])
  end
end