Class: Stew::Community::SteamId

Inherits:
Object
  • Object
show all
Defined in:
lib/stew/community/steam_id.rb

Overview

The base class for all Steam Ids. Has accessors for the base profile, games and friends of a Steam Id

Examples:

Create an instance from a 64-bit steam id

Stew::Community::SteamId.new(76561197992917668) #=> Stew::Community::SteamId

Create an instance from a community URL

Stew::Community::SteamId.create("http://steamcommunity.com/profiles/76561197992917668") #=> Stew::Community::SteamId

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(steam_id, opts = {}) ⇒ SteamId

Returns a new instance of SteamId.



23
24
25
26
# File 'lib/stew/community/steam_id.rb', line 23

def initialize(steam_id,opts={})
  @id = steam_id
  @client = opts[:client] || self.class.client_with_options(steam_id)
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



14
15
16
# File 'lib/stew/community/steam_id.rb', line 14

def id
  @id
end

Class Method Details

.create(data) ⇒ Object



16
17
18
19
20
21
# File 'lib/stew/community/steam_id.rb', line 16

def self.create(data)
  return self.new($1.to_i) if data =~ /steamcommunity.com\/profiles\/([0-9]+)/
  return self.new($1) if data =~ /steamcommunity.com\/id\/([a-zA-Z0-9]+)/
  return self.new(data) if data.to_s.match /^[0-9A-Za-z]+$/
  raise SteamIdNotFoundError
end

Instance Method Details

#friendsObject



36
37
38
# File 'lib/stew/community/steam_id.rb', line 36

def friends
  @friends ||= @client.profile_friends @id
end

#gamesObject



32
33
34
# File 'lib/stew/community/steam_id.rb', line 32

def games
  @games ||= @client.profile_games @id
end

#profileObject



28
29
30
# File 'lib/stew/community/steam_id.rb', line 28

def profile
  @profile ||= @client.profile @id
end