class ChromedriverScreenshot::Row

Public Class Methods

from_boundaries(boundaries) click to toggle source
# File lib/chromedriver-screenshot/row.rb, line 3
def self.from_boundaries(boundaries)
  row_ary = []
  boundaries.inject(0) do |row_top, row_bottom|
    row_ary << new(row_top, row_bottom)
    row_bottom
  end
  row_ary
end
new(row_top, row_bottom) click to toggle source
# File lib/chromedriver-screenshot/row.rb, line 35
def initialize(row_top, row_bottom)
  bounds = column_boundaries
  @tiles = Tile.from_boundaries(row_top, row_bottom, column_boundaries)
end

Public Instance Methods

screenshot() click to toggle source
# File lib/chromedriver-screenshot/row.rb, line 12
def screenshot
  tiles = @tiles.map { |tile| tile.screenshot }

  return tiles.first if tiles.count == 1

  row_width = tiles.inject(0) do |width, tile|
    width += tile.width
  end
  row_height = tiles.first.height # assume all tiles have same height
  screenshot = ChunkyPNG::Image.new(row_width, row_height)

  (1..row_height).each do |row|
    new_row = tiles.inject([]) do |concatenated_row, tile|
      concatenated_row += tile.row(row - 1)
    end
    screenshot.replace_row!(row - 1, new_row)
  end

  screenshot
end

Private Instance Methods

column_boundaries() click to toggle source
# File lib/chromedriver-screenshot/row.rb, line 40
def column_boundaries
  column_boundary_ary = []

  platform = ChromedriverScreenshot::Platforms.platform

  new_boundary = platform.window_width
  while new_boundary < platform.page_width
    column_boundary_ary << new_boundary
    new_boundary += platform.window_width
  end
  column_boundary_ary << platform.page_width
end