-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathresponse.rb
More file actions
45 lines (36 loc) · 810 Bytes
/
response.rb
File metadata and controls
45 lines (36 loc) · 810 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
module NP
class Response
def initialize(body)
body = JSON.parse(body, symbolize_names: true)
@report = body[:report]
end
def stars
@stars ||= @report[:stars].map do |id, props|
s = Star.new(self)
s.id = id
s.name = props[:n]
s.player_id = props[:puid]
s
end
end
def fleets
@fleets ||= @report[:fleets].map do |id, props|
f = Fleet.new(self)
f.id = id
f.name = props[:n]
f.orders = props[:o]
f.player_id = props[:puid]
f.ships_count = props[:st]
f
end
end
def players
@players ||= @report[:players].map do |id, props|
p = Player.new(self)
p.id = id
p.name = props[:alias]
p
end
end
end
end