Class: Etwin::Hammerfest::ShortHammerfestUser

Inherits:
Object
  • Object
show all
Extended by:
T::Helpers, T::Sig
Defined in:
lib/etwin/hammerfest/short_hammerfest_user.rb

Overview

Hammerfest user reference with username

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server, id, username) ⇒ ShortHammerfestUser

Returns a new instance of ShortHammerfestUser.



23
24
25
26
27
28
# File 'lib/etwin/hammerfest/short_hammerfest_user.rb', line 23

def initialize(server, id, username)
  @server = T.let(server, HammerfestServer)
  @id = T.let(id, HammerfestUserId)
  @username = T.let(username, HammerfestUsername)
  freeze
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



17
18
19
# File 'lib/etwin/hammerfest/short_hammerfest_user.rb', line 17

def id
  @id
end

#serverObject (readonly)

Returns the value of attribute server.



14
15
16
# File 'lib/etwin/hammerfest/short_hammerfest_user.rb', line 14

def server
  @server
end

#usernameObject (readonly)

Returns the value of attribute username.



20
21
22
# File 'lib/etwin/hammerfest/short_hammerfest_user.rb', line 20

def username
  @username
end

Class Method Details

.deserialize(raw) ⇒ Object



94
95
96
97
98
99
# File 'lib/etwin/hammerfest/short_hammerfest_user.rb', line 94

def deserialize(raw)
  server = HammerfestServer.deserialize(raw['server'])
  id = HammerfestUserId.new(raw['id'])
  username = HammerfestUsername.new(raw['username'])
  new(server, id, username)
end

.from_json(json_str) ⇒ Object



89
90
91
# File 'lib/etwin/hammerfest/short_hammerfest_user.rb', line 89

def from_json(json_str)
  deserialize JSON.parse(json_str)
end

Instance Method Details

#==(other) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/etwin/hammerfest/short_hammerfest_user.rb', line 31

def ==(other)
  case other
  when ShortHammerfestUser
    @server == other.server && @id == other.id && @username == other.username
  else
    false
  end
end

#as_jsonObject



52
53
54
55
56
57
58
# File 'lib/etwin/hammerfest/short_hammerfest_user.rb', line 52

def as_json
  {
    'server' => @server.serialize,
    'id' => @id.as_json,
    'username' => @username.as_json
  }
end

#hashObject



41
42
43
# File 'lib/etwin/hammerfest/short_hammerfest_user.rb', line 41

def hash
  [@server, @id, @username].hash
end

#inspectObject



61
62
63
# File 'lib/etwin/hammerfest/short_hammerfest_user.rb', line 61

def inspect
  PP.singleline_pp(self, String.new)
end

#pretty_print(pp) ⇒ Object

rubocop:disable Metrics/MethodLength



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/etwin/hammerfest/short_hammerfest_user.rb', line 66

def pretty_print(pp) # rubocop:disable Metrics/MethodLength
  pp.group(0, "#{self.class.name}(", ')') do
    pp.nest 1 do
      pp.breakable ''
      pp.text 'server='
      pp.pp @server
      pp.text ','
      pp.breakable ''
      pp.text 'id='
      pp.pp @id
      pp.text ','
      pp.breakable ''
      pp.text 'username='
      pp.pp @username
    end
    pp.breakable ''
  end
end

#to_json(opts = nil) ⇒ Object



47
48
49
# File 'lib/etwin/hammerfest/short_hammerfest_user.rb', line 47

def to_json(opts = nil)
  JSON.generate(as_json, opts)
end