Class: Etwin::Twinoid::ShortTwinoidUser
- Inherits:
-
Object
- Object
- Etwin::Twinoid::ShortTwinoidUser
- Extended by:
- T::Helpers, T::Sig
- Defined in:
- lib/etwin/twinoid/short_twinoid_user.rb
Overview
Twinoid user reference with enough data to display it
Instance Attribute Summary collapse
-
#display_name ⇒ Object
readonly
Returns the value of attribute display_name.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #as_json ⇒ Object
- #hash ⇒ Object
-
#initialize(id, display_name) ⇒ ShortTwinoidUser
constructor
A new instance of ShortTwinoidUser.
- #inspect ⇒ Object
-
#pretty_print(pp) ⇒ Object
rubocop:disable Metrics/MethodLength.
- #to_json(opts = nil) ⇒ Object
Constructor Details
#initialize(id, display_name) ⇒ ShortTwinoidUser
Returns a new instance of ShortTwinoidUser.
20 21 22 23 24 |
# File 'lib/etwin/twinoid/short_twinoid_user.rb', line 20 def initialize(id, display_name) @id = T.let(id, TwinoidUserId) @display_name = T.let(display_name, TwinoidUserDisplayName) freeze end |
Instance Attribute Details
#display_name ⇒ Object (readonly)
Returns the value of attribute display_name.
17 18 19 |
# File 'lib/etwin/twinoid/short_twinoid_user.rb', line 17 def display_name @display_name end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
14 15 16 |
# File 'lib/etwin/twinoid/short_twinoid_user.rb', line 14 def id @id end |
Class Method Details
.deserialize(raw) ⇒ Object
85 86 87 88 89 |
# File 'lib/etwin/twinoid/short_twinoid_user.rb', line 85 def deserialize(raw) id = TwinoidUserId.new(raw['id']) display_name = TwinoidUserDisplayName.new(raw['display_name']) new(id, display_name) end |
.from_json(json_str) ⇒ Object
80 81 82 |
# File 'lib/etwin/twinoid/short_twinoid_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/twinoid/short_twinoid_user.rb', line 27 def ==(other) case other when ShortTwinoidUser @id == other.id && @display_name == other.display_name else false end end |
#as_json ⇒ Object
48 49 50 51 52 53 |
# File 'lib/etwin/twinoid/short_twinoid_user.rb', line 48 def as_json { 'id' => @id.as_json, 'display_name' => @display_name.as_json } end |
#hash ⇒ Object
37 38 39 |
# File 'lib/etwin/twinoid/short_twinoid_user.rb', line 37 def hash [@id, @display_name].hash end |
#inspect ⇒ Object
56 57 58 |
# File 'lib/etwin/twinoid/short_twinoid_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/twinoid/short_twinoid_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/twinoid/short_twinoid_user.rb', line 43 def to_json(opts = nil) JSON.generate(as_json, opts) end |