Class: Stew::Community::SteamIdResolver

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

Overview

Resolves steam ids from numbers, urls and vanity names

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client = Stew.config[:default_community_client].new) ⇒ SteamIdResolver

Returns a new instance of SteamIdResolver.



8
9
10
# File 'lib/stew/community/steam_id_resolver.rb', line 8

def initialize(client = Stew.config[:default_community_client].new)
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



6
7
8
# File 'lib/stew/community/steam_id_resolver.rb', line 6

def client
  @client
end

Instance Method Details

#steam_id(data) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/stew/community/steam_id_resolver.rb', line 12

def steam_id(data)
  data_string = data.to_s
  return data.to_i if /^[0-9]+$/ === data_string

  matches = (/steamcommunity.com\/(id|profiles|)\/([a-z0-9]+)/i).match(data_string)
  steam_id = steam_id_from_matches(data,matches)
  return steam_id unless steam_id.nil?
  raise Stew::Community::SteamIdNotFoundError
end