Class: Rsteamshot::ScreenshotPaginator

Inherits:
Object
  • Object
show all
Defined in:
lib/rsteamshot/screenshot_paginator.rb

Overview

Public: Use to paginate screenshots fetched from Steam in chunks of fewer than 50 per page.

Instance Method Summary collapse

Constructor Details

#initialize(process_html, max_per_page:, per_page: 10, steam_per_page:) ⇒ ScreenshotPaginator

Public: Construct a new ScreenshotPaginator that will process a page of HTML using the given lambda.

process_html - a lambda that will take a Mechanize::Page and return a list of

Rsteamshot::Screenshot instances found in that page

max_per_page - the most screenshots that can be returned in a page, based on how many

screenshots can be shown on the Steam page

per_page - how many screenshots you want returned; Integer; should be less than or

equal to max_per_page

steam_per_page - how many screenshots will actually be on the Steam page; Integer; should be

less than or equal to max_per_page


16
17
18
19
20
21
22
# File 'lib/rsteamshot/screenshot_paginator.rb', line 16

def initialize(process_html, max_per_page:, per_page: 10, steam_per_page:)
  @process_html = process_html
  @screenshot_pages = []
  @max_per_page = max_per_page
  @raw_per_page = per_page
  @steam_per_page = normalize_per_page(steam_per_page)
end

Instance Method Details

#per_pageObject

Public: Returns the Integer count of screenshots per page.



25
26
27
# File 'lib/rsteamshot/screenshot_paginator.rb', line 25

def per_page
  @per_page = normalize_per_page(@raw_per_page)
end

#screenshots(page: 1, url:) ⇒ Object

Public: Get the specified number of screenshots from the given Steam URL.

page - which page of results to fetch; Integer; defaults to 1 url - URL to a Steam page with screenshots, should not include a page parameter; String

Returns an Array of Rsteamshot::Screenshots.



35
36
37
38
# File 'lib/rsteamshot/screenshot_paginator.rb', line 35

def screenshots(page: 1, url:)
  offset = get_offset(page)
  fetch_screenshots(offset, url).drop(offset).take(per_page)
end