-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathobjects.rb
More file actions
47 lines (35 loc) · 890 Bytes
/
objects.rb
File metadata and controls
47 lines (35 loc) · 890 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
46
47
module NP
class BaseObject
def initialize(response)
@response = response
end
end
class Star < BaseObject
attr_accessor :id, :name, :player_id
def player
@response.players.find { |p| p.id.to_s == player_id.to_s }
end
end
class FleetOrder < BaseObject
attr_accessor :destination_star_id, :ships_count
def destination_star
@response.stars.find { |s| s.id.to_s == destination_star_id.to_s }
end
end
class Fleet < BaseObject
attr_accessor :id, :player_id, :name, :ships_count, :orders
def player
@response.players.find { |p| p.id.to_s == player_id.to_s }
end
def orders=(values)
@orders = values.map do |order|
o = FleetOrder.new(@response)
o.destination_star_id = order[1]
o
end
end
end
class Player < BaseObject
attr_accessor :id, :name
end
end