Class: ESM::Message::Player

Inherits:
Object
  • Object
show all
Defined in:
lib/esm/message/player.rb

Direct Known Subclasses

Target

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from(user) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/esm/message/player.rb', line 6

def self.from(user)
  # Creates a hash with the keys being the keys of this class, and the value of nil
  # Allows for defaulting the values since ImmutableStruct requires a value of some sort
  data = members.zip([nil]).to_h

  case user
  when ESM::User
    data.merge!(
      steam_uid: user.steam_uid,
      discord_id: user.discord_id,
      discord_name: user.discord_username,
      discord_mention: user.mention
    )
  when ESM::User::Ephemeral
    # Having steam_uid as the default saves work for the A3 server
    data[:steam_uid] = user.steam_uid
    data[:discord_mention] = user.mention
    data[:discord_name] = user.mention
  else
    data.merge!(user)
  end

  new(**data)
end

Instance Method Details

#to_hObject



31
32
33
# File 'lib/esm/message/player.rb', line 31

def to_h
  super.delete_if { |_k, v| v.nil? }
end