class Rsteamshot::ScreenshotPage

Public: Represents a page of screenshots on Steam.

Attributes

number[R]

Public: Returns the Integer number of this page.

per_page[R]

Public: Returns the Integer count of how many screenshots to fetch per page.

screenshots[R]

Public: Returns an Array of the Rsteamshot::Screenshots found on this page.

Public Class Methods

new(number, per_page) click to toggle source

Public: Construct a new ScreenshotPage with the given page number.

number - the page number; Integer per_page - how many screenshots are shown on the Steam page

# File lib/rsteamshot/screenshot_page.rb, line 17
def initialize(number, per_page)
  @number = number
  @per_page = per_page
end

Public Instance Methods

fetch(base_url) { |html| ... } click to toggle source

Public: Fetch the contents of this page from Steam.

Returns a Mechanize::Page.

# File lib/rsteamshot/screenshot_page.rb, line 34
def fetch(base_url)
  return if @screenshots # already fetched

  url = with_steam_page_param(base_url)
  Mechanize.new.get(url) do |html|
    @screenshots = yield(html)
  end
end
includes_screenshot?(screenshot_number) click to toggle source

Public: Check if the nth screenshot would be on this page on Steam.

screenshot_number - the index of the screenshot you want to check

Returns a Boolean.

# File lib/rsteamshot/screenshot_page.rb, line 27
def includes_screenshot?(screenshot_number)
  range.cover?(screenshot_number)
end

Private Instance Methods

max_screenshot() click to toggle source
# File lib/rsteamshot/screenshot_page.rb, line 49
def max_screenshot
  min_screenshot + per_page
end
min_screenshot() click to toggle source
# File lib/rsteamshot/screenshot_page.rb, line 45
def min_screenshot
  (number - 1) * per_page
end
range() click to toggle source
# File lib/rsteamshot/screenshot_page.rb, line 53
def range
  min_screenshot...max_screenshot
end
with_steam_page_param(base_url) click to toggle source
# File lib/rsteamshot/screenshot_page.rb, line 57
def with_steam_page_param(base_url)
  joiner = base_url.include?('?') ? '&' : '?'
  "#{base_url}#{joiner}p=#{number}"
end