Class: Overlook::Csgo::SharecodeDecoder

Inherits:
Object
  • Object
show all
Defined in:
lib/overlook/csgo/sharecode_decoder.rb

Constant Summary collapse

InvalidShareCode =
Class.new(StandardError)
DecodingError =
Class.new(StandardError)
DICTIONARY =
"ABCDEFGHJKLMNOPQRSTUVWXYZabcdefhijkmnopqrstuvwxyz23456789".freeze
DICTIONARY_LENGTH =
DICTIONARY.length.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_code) ⇒ SharecodeDecoder

Returns a new instance of SharecodeDecoder.



14
15
16
# File 'lib/overlook/csgo/sharecode_decoder.rb', line 14

def initialize(_code)
  @code = _code.dup
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



12
13
14
# File 'lib/overlook/csgo/sharecode_decoder.rb', line 12

def code
  @code
end

Instance Method Details

#decodeObject



18
19
20
21
22
23
24
25
26
27
# File 'lib/overlook/csgo/sharecode_decoder.rb', line 18

def decode
  sanitize_code!

  reader     = ByteReader.new(io)
  matchid    = reader.read_int64
  outcomeid  = reader.read_int64
  tokenid    = reader.read_short

  { matchid: matchid.to_s, outcomeid: outcomeid.to_s, tokenid: tokenid.to_s }
end