2013-07-09 21:40:21 +00:00
|
|
|
class Snapshot
|
2013-07-25 16:02:58 +00:00
|
|
|
|
2013-08-27 18:02:40 +00:00
|
|
|
delegate :width, :height, :cell, :to => :grid
|
2013-08-04 21:12:18 +00:00
|
|
|
|
2013-08-27 18:02:40 +00:00
|
|
|
def self.build(data)
|
|
|
|
data = data.map { |cells|
|
|
|
|
cells.map { |cell|
|
|
|
|
Cell.new(cell[0], Brush.new(cell[1]))
|
|
|
|
}
|
|
|
|
}
|
2013-08-14 15:24:36 +00:00
|
|
|
|
2013-08-27 18:02:40 +00:00
|
|
|
grid = Grid.new(data)
|
2013-08-14 15:24:36 +00:00
|
|
|
|
2013-08-27 18:02:40 +00:00
|
|
|
new(grid)
|
2013-08-14 15:24:36 +00:00
|
|
|
end
|
|
|
|
|
2013-08-27 18:02:40 +00:00
|
|
|
def initialize(grid)
|
|
|
|
@grid = grid
|
2013-08-25 18:49:23 +00:00
|
|
|
end
|
|
|
|
|
2013-08-27 18:02:40 +00:00
|
|
|
def thumbnail(w, h)
|
|
|
|
x = 0
|
|
|
|
y = height - h - grid.trailing_empty_lines
|
|
|
|
y = 0 if y < 0
|
|
|
|
cropped_grid = grid.crop(x, y, w, h)
|
2013-08-05 16:18:49 +00:00
|
|
|
|
2013-08-27 18:02:40 +00:00
|
|
|
self.class.new(cropped_grid)
|
2013-07-09 21:40:21 +00:00
|
|
|
end
|
2013-07-25 16:02:58 +00:00
|
|
|
|
2013-08-25 18:49:23 +00:00
|
|
|
private
|
2013-08-04 21:12:18 +00:00
|
|
|
|
2013-08-27 18:02:40 +00:00
|
|
|
attr_reader :grid
|
2013-08-25 18:49:23 +00:00
|
|
|
|
2013-07-09 21:40:21 +00:00
|
|
|
end
|