class ChromedriverScreenshot::Tile

Public Class Methods

from_boundaries(row_top, row_bottom, boundaries) click to toggle source
# File lib/chromedriver-screenshot/tile.rb, line 3
def self.from_boundaries(row_top, row_bottom, boundaries)
  tile_ary = []
  boundaries.inject(0) do |column_left, column_right|
    tile_ary << new([column_left, row_top], [column_right, row_bottom])
    column_right
  end
  tile_ary
end
new(top_left, bot_right) click to toggle source
# File lib/chromedriver-screenshot/tile.rb, line 12
def initialize(top_left, bot_right)
  @x, @y = top_left
  @width = bot_right[0] - @x
  @height = bot_right[1] - @y
end

Public Instance Methods

screenshot() click to toggle source
# File lib/chromedriver-screenshot/tile.rb, line 18
def screenshot
  screenshot_blob = get_screenshot
  offset_x, offset_y = get_offset
  screenshot = ChunkyPNG::Image.from_blob(screenshot_blob)
  screenshot.crop(offset_x, offset_y, @width, @height)
end

Private Instance Methods

get_offset() click to toggle source

can't scroll past ends of page, so sometimes position won't be accurate

# File lib/chromedriver-screenshot/tile.rb, line 34
def get_offset
  platform = ChromedriverScreenshot::Platforms.platform
  offset_x = @x - platform.window_x
  offset_y = @y - platform.window_y
  [offset_x, offset_y]
end
get_screenshot() click to toggle source
# File lib/chromedriver-screenshot/tile.rb, line 27
def get_screenshot
  platform = ChromedriverScreenshot::Platforms.platform
  platform.scroll_to @x, @y
  platform.screenshot
end