forked from AdaGold/solar-system
-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathplanet.rb
32 lines (26 loc) · 1.05 KB
/
planet.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
class Planet
attr_reader :name, :color, :mass_kg, :distance_from_sun_km, :fun_fact
def initialize(name, color, mass_kg, distance_from_sun_km, fun_fact)
@name = name
@color = color
if (mass_kg.class == Float || mass_kg.class == Integer) && mass_kg > 0
@mass_kg = mass_kg
else
raise ArgumentError, "For #{self.name}, this isn't the right type of input for mass in kg - please enter an number greater than 0."
end
if (distance_from_sun_km.class == Float || distance_from_sun_km.class == Integer) && distance_from_sun_km > 0
@distance_from_sun_km = distance_from_sun_km
else
raise ArgumentError, "For #{self.name}, this isn't the right type of input for distance from sun in km - please enter an number greater than 0."
end
@fun_fact = fun_fact
end
def summary
stats = "<< Summary of planet: #{name.upcase} >>\n" +
"Color: #{color}\n" +
"Mass (kg): #{mass_kg}\n" +
"Distance from sun (km): #{distance_from_sun_km}\n" +
"Fun fact: #{fun_fact}"
return stats
end
end