-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobservable.rb
47 lines (39 loc) · 866 Bytes
/
observable.rb
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 Observable
def to_s
@name
end
def info
# appearance
description = "#{@name}."
if @appearance
description += " #{@appearance}"
end
# equipment
if @main_hand
description += " It wields a #{@main_hand}."
end
# stats
if @health && @max_hp
healthiness = "Healthy"
if @health < @max_hp / 4
healthiness = "Near death"
elsif @health < @max_hp / 2
healthiness = "Injured"
elsif @health < @max_hp
healthiness = "Hurt"
end
end
# child info
if @main_hand
description += indent("\n└#{@main_hand.info}")
end
if @actors
actor_info = @actors.map { |actor| actor.info }
description += indent("\n└#{actor_info.join("\n└")}")
end
return description
end
def indent(str)
str.gsub(/^/, ' ')
end
end