Id
Valve's SteamId data type in Ruby.
Installation
Add this line to your application's Gemfile:
gem 'steam-id'
And then execute:
$ bundle
Or install it yourself as:
$ gem install steam-id
Usage
# Create from Community Id
id = CommunityId.parse(76561197998193728)
# Create from a Steam2 Id
id = Steam2Id.parse('STEAM_0:0:18964000')
# Create from a Steam3Id
id = Steam3Id.parse('[U:1:37928000]')
The #parse
method returns nil if the parsing fails. Parsing can be a success
but the Steam Id can still be invalid. To determine validity of the Steam ID a
#valid?
method is provided.
# Create from Community Id
id = CommunityId.parse(76561197998193728)
id.valid? # => true
id = Steam2Id.parse('STEAM_0:0:0')
id.valid? # => false
A #to_s
and #to_i
method are also provided for representing the object in
String and Integer form. By default #to_s
returns the Steam2 string
representation. A printer class can be passed to #to_s
to render in different
formats. The #to_i
method returns the 64 bit steam id.
# Create from Community Id
id = CommunityId.parse(76561197998193728)
id.to_s # => 'STEAM_0:0:18964000'
id.to_s(Steam::Id::Steam3Printer) # => '[U:1:37928000]'
id = Steam2Id.parse('STEAM_0:0:18964000')
id.to_i # => 76561197998193728
Limitations
Steam3 ID support is limited to account types of "Individual"