Class: Etwin::Link::HammerfestLink

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

Overview

Link to a Hammerfest user from an Eternal-Twin user

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(link, unlink, user) ⇒ HammerfestLink

Returns a new instance of HammerfestLink.



25
26
27
28
29
30
# File 'lib/etwin/link/hammerfest_link.rb', line 25

def initialize(link, unlink, user)
  @link = T.let(link, LinkAction)
  @unlink = T.let(unlink, T.nilable(LinkAction))
  @user = T.let(user, Etwin::Hammerfest::ShortHammerfestUser)
  freeze
end

Instance Attribute Details

Returns the value of attribute link.



14
15
16
# File 'lib/etwin/link/hammerfest_link.rb', line 14

def link
  @link
end

Returns the value of attribute unlink.



17
18
19
# File 'lib/etwin/link/hammerfest_link.rb', line 17

def unlink
  @unlink
end

#userObject (readonly)

Returns the value of attribute user.



20
21
22
# File 'lib/etwin/link/hammerfest_link.rb', line 20

def user
  @user
end

Class Method Details

.deserialize(raw) ⇒ Object



96
97
98
99
100
101
102
# File 'lib/etwin/link/hammerfest_link.rb', line 96

def deserialize(raw)
  link = LinkAction.deserialize(raw['link'])
  raw_unlink = raw['unlink']
  unlink = raw_unlink.nil? ? nil : LinkAction.deserialize(raw_unlink)
  user = Etwin::Hammerfest::ShortHammerfestUser.deserialize(raw['user'])
  new(link, unlink, user)
end

.from_json(json_str) ⇒ Object



91
92
93
# File 'lib/etwin/link/hammerfest_link.rb', line 91

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

Instance Method Details

#==(other) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/etwin/link/hammerfest_link.rb', line 33

def ==(other)
  case other
  when HammerfestLink
    @link == other.link && @unlink == other.unlink && @user == other.user
  else
    false
  end
end

#as_jsonObject



54
55
56
57
58
59
60
# File 'lib/etwin/link/hammerfest_link.rb', line 54

def as_json
  {
    'link' => @link.as_json,
    'unlink' => @unlink.nil? ? nil : @unlink.as_json,
    'user' => @user.as_json
  }
end

#hashObject



43
44
45
# File 'lib/etwin/link/hammerfest_link.rb', line 43

def hash
  [@link, @unlink, @user].hash
end

#inspectObject



63
64
65
# File 'lib/etwin/link/hammerfest_link.rb', line 63

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

#pretty_print(pp) ⇒ Object

rubocop:disable Metrics/MethodLength



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/etwin/link/hammerfest_link.rb', line 68

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

#to_json(opts = nil) ⇒ Object



49
50
51
# File 'lib/etwin/link/hammerfest_link.rb', line 49

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