Class: Rsteamshot::ScreenshotPage

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

Overview

Public: Represents a page of screenshots on Steam.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(number, per_page) ⇒ ScreenshotPage

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



17
18
19
20
# File 'lib/rsteamshot/screenshot_page.rb', line 17

def initialize(number, per_page)
  @number = number
  @per_page = per_page
end

Instance Attribute Details

#numberObject (readonly)

Public: Returns the Integer number of this page.



5
6
7
# File 'lib/rsteamshot/screenshot_page.rb', line 5

def number
  @number
end

#per_pageObject (readonly)

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



8
9
10
# File 'lib/rsteamshot/screenshot_page.rb', line 8

def per_page
  @per_page
end

#screenshotsObject (readonly)

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



11
12
13
# File 'lib/rsteamshot/screenshot_page.rb', line 11

def screenshots
  @screenshots
end

Instance Method Details

#fetch(base_url) ⇒ Object

Public: Fetch the contents of this page from Steam.

Returns a Mechanize::Page.



34
35
36
37
38
39
40
41
# 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) ⇒ Boolean

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.

Returns:

  • (Boolean)


27
28
29
# File 'lib/rsteamshot/screenshot_page.rb', line 27

def includes_screenshot?(screenshot_number)
  range.cover?(screenshot_number)
end