Class: Etwin::User::ShortUser

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

Overview

User with minimum data to identify and display them

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, display_name) ⇒ ShortUser

Returns a new instance of ShortUser.



20
21
22
23
24
# File 'lib/etwin/user/short_user.rb', line 20

def initialize(id, display_name)
  @id = T.let(id, UserId)
  @display_name = T.let(display_name, UserDisplayNameVersions)
  freeze
end

Instance Attribute Details

#display_nameObject (readonly)

Returns the value of attribute display_name.



17
18
19
# File 'lib/etwin/user/short_user.rb', line 17

def display_name
  @display_name
end

#idObject (readonly)

Returns the value of attribute id.



14
15
16
# File 'lib/etwin/user/short_user.rb', line 14

def id
  @id
end

Class Method Details

.deserialize(raw) ⇒ Object



85
86
87
88
89
# File 'lib/etwin/user/short_user.rb', line 85

def deserialize(raw)
  id = UserId.new(raw['id'])
  display_name = UserDisplayNameVersions.deserialize(raw['display_name'])
  new(id, display_name)
end

.from_json(json_str) ⇒ Object



80
81
82
# File 'lib/etwin/user/short_user.rb', line 80

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

Instance Method Details

#==(other) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/etwin/user/short_user.rb', line 27

def ==(other)
  case other
  when ShortUser
    @id == other.id && @display_name == other.display_name
  else
    false
  end
end

#as_jsonObject



48
49
50
51
52
53
# File 'lib/etwin/user/short_user.rb', line 48

def as_json
  {
    'id' => @id.as_json,
    'display_name' => @display_name.as_json
  }
end

#hashObject



37
38
39
# File 'lib/etwin/user/short_user.rb', line 37

def hash
  [@id, @display_name].hash
end

#inspectObject



56
57
58
# File 'lib/etwin/user/short_user.rb', line 56

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

#pretty_print(pp) ⇒ Object

rubocop:disable Metrics/MethodLength



61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/etwin/user/short_user.rb', line 61

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

#to_json(opts = nil) ⇒ Object



43
44
45
# File 'lib/etwin/user/short_user.rb', line 43

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