Class: Rsteamshot::Screenshot
- Inherits:
-
Object
- Object
- Rsteamshot::Screenshot
- Defined in:
- lib/rsteamshot/screenshot.rb
Overview
Public: Represents an image that has been uploaded to Steam of a screenshot taken in a Steam app.
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Public: Returns the Rsteamshot::App in which this screenshot was taken.
-
#comment_count ⇒ Object
readonly
Public: Returns Integer count of how many comments people have left on this screenshot.
-
#date ⇒ Object
readonly
Public: Returns the DateTime when this screenshot was uploaded.
-
#details_url ⇒ Object
readonly
Public: Returns String URL to the Steam page that shows details about this screenshot.
-
#file_size ⇒ Object
readonly
Public: Returns a String describing how large the screenshot is, e.g., 0.547 MB.
-
#full_size_url ⇒ Object
readonly
Public: Returns String URL to the full-size image.
-
#height ⇒ Object
readonly
Public: Returns Integer pixel height of the screenshot.
-
#like_count ⇒ Object
readonly
Public: Returns Integer count of how many people have voted for this screenshot.
-
#medium_url ⇒ Object
readonly
Public: Returns String URL to a medium-size version of the image.
-
#title ⇒ Object
readonly
Public: Returns a String of how the user described this screenshot, or nil.
-
#user_name ⇒ Object
readonly
Public: Returns String name of the Steam user who uploaded the screenshot.
-
#user_url ⇒ Object
readonly
Public: Returns String URL to the profile of the Steam user who uploaded the screenshot.
-
#width ⇒ Object
readonly
Public: Returns Integer pixel width of the screenshot.
Instance Method Summary collapse
-
#file_size_in_bytes ⇒ Object
Public: file_size parsed into bytes.
-
#initialize(attrs = {}) ⇒ Screenshot
constructor
Public: Initialize a screenshot with the given attributes.
-
#inspect ⇒ Object
Public: A detailed representation of this screenshot.
-
#to_h ⇒ Object
Public: Get a hash representation of this screenshot.
-
#to_json ⇒ Object
Public: Get a JSON representation of this screenshot.
Constructor Details
#initialize(attrs = {}) ⇒ Screenshot
Public: Initialize a screenshot with the given attributes.
attrs - the Hash of attributes for this screenshot
:title - how the user described this screenshot
:details_url - URL to the Steam page that shows details about this screenshot
:full_size_url - URL to the full-size image
:medium_url - URL to a medium-size version of the image
:user_name - name of the Steam user who uploaded the screenshot
:user_url - URL to the profile of the Steam user who uploaded the screenshot
:date - the date and time when this screenshot was uploaded
:file_size - describes how large the screenshot is, e.g., 0.547 MB
:width - pixel width of the screenshot
:height - pixel height of the screenshot
:like_count - number of likes this screenshot has on Steam
:comment_count - number of comments this screenshot has received on Steam
59 60 61 62 63 |
# File 'lib/rsteamshot/screenshot.rb', line 59 def initialize(attrs = {}) attrs.each { |key, value| instance_variable_set("@#{key}", value) } fetch_details unless has_details? end |
Instance Attribute Details
#app ⇒ Object (readonly)
Public: Returns the Rsteamshot::App in which this screenshot was taken.
42 43 44 |
# File 'lib/rsteamshot/screenshot.rb', line 42 def app @app end |
#comment_count ⇒ Object (readonly)
Public: Returns Integer count of how many comments people have left on this screenshot.
39 40 41 |
# File 'lib/rsteamshot/screenshot.rb', line 39 def comment_count @comment_count end |
#date ⇒ Object (readonly)
Public: Returns the DateTime when this screenshot was uploaded.
24 25 26 |
# File 'lib/rsteamshot/screenshot.rb', line 24 def date @date end |
#details_url ⇒ Object (readonly)
Public: Returns String URL to the Steam page that shows details about this screenshot.
9 10 11 |
# File 'lib/rsteamshot/screenshot.rb', line 9 def details_url @details_url end |
#file_size ⇒ Object (readonly)
Public: Returns a String describing how large the screenshot is, e.g., 0.547 MB.
27 28 29 |
# File 'lib/rsteamshot/screenshot.rb', line 27 def file_size @file_size end |
#full_size_url ⇒ Object (readonly)
Public: Returns String URL to the full-size image.
12 13 14 |
# File 'lib/rsteamshot/screenshot.rb', line 12 def full_size_url @full_size_url end |
#height ⇒ Object (readonly)
Public: Returns Integer pixel height of the screenshot.
33 34 35 |
# File 'lib/rsteamshot/screenshot.rb', line 33 def height @height end |
#like_count ⇒ Object (readonly)
Public: Returns Integer count of how many people have voted for this screenshot.
36 37 38 |
# File 'lib/rsteamshot/screenshot.rb', line 36 def like_count @like_count end |
#medium_url ⇒ Object (readonly)
Public: Returns String URL to a medium-size version of the image.
15 16 17 |
# File 'lib/rsteamshot/screenshot.rb', line 15 def medium_url @medium_url end |
#title ⇒ Object (readonly)
Public: Returns a String of how the user described this screenshot, or nil.
6 7 8 |
# File 'lib/rsteamshot/screenshot.rb', line 6 def title @title end |
#user_name ⇒ Object (readonly)
Public: Returns String name of the Steam user who uploaded the screenshot.
18 19 20 |
# File 'lib/rsteamshot/screenshot.rb', line 18 def user_name @user_name end |
#user_url ⇒ Object (readonly)
Public: Returns String URL to the profile of the Steam user who uploaded the screenshot.
21 22 23 |
# File 'lib/rsteamshot/screenshot.rb', line 21 def user_url @user_url end |
#width ⇒ Object (readonly)
Public: Returns Integer pixel width of the screenshot.
30 31 32 |
# File 'lib/rsteamshot/screenshot.rb', line 30 def width @width end |
Instance Method Details
#file_size_in_bytes ⇒ Object
Public: file_size parsed into bytes
Returns a Integer
102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/rsteamshot/screenshot.rb', line 102 def file_size_in_bytes unit_multiplier = 1000 size, unit = self.file_size.split(' ') bytes = case unit.downcase when 'kb' then size.to_f * unit_multiplier when 'mb' then size.to_f * (unit_multiplier ** 2) when 'gb' then size.to_f * (unit_multiplier ** 3) else size.to_f end bytes.to_i end |
#inspect ⇒ Object
Public: A detailed representation of this screenshot.
Returns a String.
95 96 97 |
# File 'lib/rsteamshot/screenshot.rb', line 95 def inspect self.class.name + '<' + JSON.generate(to_h) + '>' end |
#to_h ⇒ Object
Public: Get a hash representation of this screenshot.
Returns a Hash.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/rsteamshot/screenshot.rb', line 68 def to_h result = { details_url: details_url } result[:title] = title if title result[:full_size_url] = full_size_url if full_size_url result[:medium_url] = medium_url if medium_url result[:user_name] = user_name if user_name result[:user_url] = user_url if user_url result[:date] = date if date result[:file_size] = file_size if file_size result[:width] = width if width result[:height] = height if height result[:like_count] = like_count if like_count result[:comment_count] = comment_count if comment_count result[:app] = app.to_h if app result end |
#to_json ⇒ Object
Public: Get a JSON representation of this screenshot.
Returns a String.
88 89 90 |
# File 'lib/rsteamshot/screenshot.rb', line 88 def to_json JSON.pretty_generate(to_h) end |