Class: Lapis::Yggdrasil::Profile

Inherits:
Object
  • Object
show all
Defined in:
lib/lapis/yggdrasil/profile.rb

Overview

Player information associated with a game.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, name, is_legacy = false) ⇒ Profile

Creates a player profile.

Parameters:

  • id (Uuid)

    Unique ID of the profile.

  • name (String)

    Displayed player name.

  • is_legacy (Boolean) (defaults to: false)

    true if the profile hasn’t been migrated to a Mojang account, or false if it has.



29
30
31
32
33
# File 'lib/lapis/yggdrasil/profile.rb', line 29

def initialize(id, name, is_legacy = false)
  @id        = id
  @name      = name.dup.freeze
  @is_legacy = !!is_legacy
end

Instance Attribute Details

#idUuid (readonly)

Unique ID of the profile.

Returns:

  • (Uuid)


11
12
13
# File 'lib/lapis/yggdrasil/profile.rb', line 11

def id
  @id
end

#legacy?Boolean (readonly)

Returns:

  • (Boolean)


21
22
23
# File 'lib/lapis/yggdrasil/profile.rb', line 21

def legacy?
  @is_legacy
end

#nameString (readonly)

Displayed player name.

Returns:

  • (String)


15
16
17
# File 'lib/lapis/yggdrasil/profile.rb', line 15

def name
  @name
end

Class Method Details

.from_properties(properties) ⇒ Profile

Creates a profile from a set of properties in a response.

Parameters:

  • properties (Hash<Symbol => String>)

    Set of properties.

Options Hash (properties):

  • :id (String)

    Unique ID of the profile.

  • :name (String)

    Displayed player name.

  • :legacy (String)

    true or false indicating whether the user hasn’t migrated to a Mojang account.

Returns:

Raises:

  • (ArgumentError)

    The :id or :name property is missing.



52
53
54
55
56
57
58
59
60
# File 'lib/lapis/yggdrasil/profile.rb', line 52

def self.from_properties(properties)
  fail ArgumentError, 'ID is required' unless properties.key?(:id)
  fail ArgumentError, 'Name is required' unless properties.key?(:name)

  id        = Lapis::Uuid.parse(properties[:id])
  name      = properties[:name]
  is_legacy = (properties.key?(:legacy) && properties[:legacy] == 'true')
  new(id, name, is_legacy)
end

Instance Method Details

#==(other) ⇒ true, false

Compares the profile to another.

Parameters:

  • other (Profile)

    Profile to compare against.

Returns:

  • (true)

    The profiles are the same.

  • (false)

    The profiles are different.



39
40
41
42
43
# File 'lib/lapis/yggdrasil/profile.rb', line 39

def ==(other)
  other.id == @id &&
      other.name == @name &&
      other.legacy? == @is_legacy
end