From 787c78474780003af29b6adc83ba5bf255a41411 Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Mon, 25 Feb 2019 13:34:55 -0800 Subject: [PATCH 01/15] created solar_sytem.rb --- solar_system.rb | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 solar_system.rb diff --git a/solar_system.rb b/solar_system.rb new file mode 100644 index 00000000..e69de29b From a9ac58f5de900f47237e76cdc5b8e4c62cf678d3 Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Mon, 25 Feb 2019 13:36:46 -0800 Subject: [PATCH 02/15] "wrong file name, mv planet.rb" --- solar_system.rb => planet.rb | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename solar_system.rb => planet.rb (100%) diff --git a/solar_system.rb b/planet.rb similarity index 100% rename from solar_system.rb rename to planet.rb From c4f8b96705cdf5955e7648e0db97777e48e2e1d0 Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Mon, 25 Feb 2019 13:49:58 -0800 Subject: [PATCH 03/15] added main and wrote Planet Class --- main.rb | 0 planet.rb | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 main.rb diff --git a/main.rb b/main.rb new file mode 100644 index 00000000..e69de29b diff --git a/planet.rb b/planet.rb index e69de29b..71e20eb1 100644 --- a/planet.rb +++ b/planet.rb @@ -0,0 +1,25 @@ +# wave 1 +require 'pry' +require 'colorize' + +class Planet + attr_reader :name, :color, :mass_kg, :distance_from_sun_km, :fun_fact + + def initialize (name: "Planet", color: "Color", mass_kg: "Mass in Kg", distance_from_sun_km: "Distance in km", fun_fact: "This is a fun fact") + @name = name + @color = color + @mass_kg = mass_kg + @distance_from_sun_km = distance_from_sun_km + @fun_fact = fun_fact + end + + def summary + puts "Hello" + end +end + +earth = Planet.new(name: "Earth", color: 'blue-green', mass_kg: '5.972e24', distance_from_sun_km: '1.496e8', fun_fact: 'Only planet known to support life') + +puts earth.color + + From 412cae8e602edf25732f7b351065b84f9d40ab10 Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Mon, 25 Feb 2019 14:09:28 -0800 Subject: [PATCH 04/15] "created two new instances of planet in main" --- main.rb | 13 +++++++++++++ planet.rb | 10 ++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/main.rb b/main.rb index e69de29b..17e2710c 100644 --- a/main.rb +++ b/main.rb @@ -0,0 +1,13 @@ +require_relative 'planet' + +def main + #... do stuff with planets... + venus = Planet.new(name: "Venus", color: 'purple', mass_kg: '3.88e10', distance_from_sun_km: '1.3e8', fun_fact: 'this planet is commonly associated with feminine energy') + + pluto = Planet.new(name: "Pluto", color: 'icy-grey', mass_kg: '0.88e10', distance_from_sun_km: '15.3999e8', fun_fact: 'Pluto was recently debunked from the official planet list!') + + puts venus.summary + puts pluto.summary +end + +main \ No newline at end of file diff --git a/planet.rb b/planet.rb index 71e20eb1..7d253068 100644 --- a/planet.rb +++ b/planet.rb @@ -8,18 +8,20 @@ class Planet def initialize (name: "Planet", color: "Color", mass_kg: "Mass in Kg", distance_from_sun_km: "Distance in km", fun_fact: "This is a fun fact") @name = name @color = color - @mass_kg = mass_kg + @mass_kg = mass_kg @distance_from_sun_km = distance_from_sun_km @fun_fact = fun_fact + @summary = summary + return summary end def summary - puts "Hello" + return "The planet #{self.name} is #{self.color} in color, has a mass of #{self.mass_kg}, is #{self.distance_from_sun_km}km from the sun. A fun fact about your planet: #{self.fun_fact}" end end +# instantiate each planet here: earth = Planet.new(name: "Earth", color: 'blue-green', mass_kg: '5.972e24', distance_from_sun_km: '1.496e8', fun_fact: 'Only planet known to support life') -puts earth.color - +p earth.mass_kg From 3372227e50631d43958895de9980e6d5e74f88a0 Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Mon, 25 Feb 2019 14:12:09 -0800 Subject: [PATCH 05/15] "wave 2 - created solar_sytem.rb" --- main.rb | 4 ++-- planet.rb | 4 +--- solar_system.rb | 0 3 files changed, 3 insertions(+), 5 deletions(-) create mode 100644 solar_system.rb diff --git a/main.rb b/main.rb index 17e2710c..54f26c7b 100644 --- a/main.rb +++ b/main.rb @@ -2,9 +2,9 @@ def main #... do stuff with planets... - venus = Planet.new(name: "Venus", color: 'purple', mass_kg: '3.88e10', distance_from_sun_km: '1.3e8', fun_fact: 'this planet is commonly associated with feminine energy') + venus = Planet.new(name: "Venus", color: 'purple', mass_kg: '3.88e10', distance_from_sun_km: '1.3e8', fun_fact: 'this planet is commonly associated with feminine energy.') - pluto = Planet.new(name: "Pluto", color: 'icy-grey', mass_kg: '0.88e10', distance_from_sun_km: '15.3999e8', fun_fact: 'Pluto was recently debunked from the official planet list!') + pluto = Planet.new(name: "Pluto", color: 'icy-grey', mass_kg: '0.887e10', distance_from_sun_km: '15.3999e8', fun_fact: 'Pluto was recently debunked from the official planet list!') puts venus.summary puts pluto.summary diff --git a/planet.rb b/planet.rb index 7d253068..fe72f7ee 100644 --- a/planet.rb +++ b/planet.rb @@ -16,12 +16,10 @@ def initialize (name: "Planet", color: "Color", mass_kg: "Mass in Kg", distance_ end def summary - return "The planet #{self.name} is #{self.color} in color, has a mass of #{self.mass_kg}, is #{self.distance_from_sun_km}km from the sun. A fun fact about your planet: #{self.fun_fact}" + return "The planet #{self.name} is #{self.color} in color, has a mass of #{self.mass_kg}kg, and is #{self.distance_from_sun_km}km from the sun. A fun fact about your planet: #{self.fun_fact}" end end # instantiate each planet here: earth = Planet.new(name: "Earth", color: 'blue-green', mass_kg: '5.972e24', distance_from_sun_km: '1.496e8', fun_fact: 'Only planet known to support life') -p earth.mass_kg - diff --git a/solar_system.rb b/solar_system.rb new file mode 100644 index 00000000..e69de29b From d777f87d7ab872ac37c8368c394f7d5832e78459 Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Mon, 25 Feb 2019 15:55:13 -0800 Subject: [PATCH 06/15] "created add_method, list_planets, and find_planet methods" --- main.rb | 21 +++++++++++++++++++-- planet.rb | 1 + solar_system.rb | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/main.rb b/main.rb index 54f26c7b..7a1e824e 100644 --- a/main.rb +++ b/main.rb @@ -1,4 +1,5 @@ require_relative 'planet' +require_relative 'solar_system' def main #... do stuff with planets... @@ -6,8 +7,24 @@ def main pluto = Planet.new(name: "Pluto", color: 'icy-grey', mass_kg: '0.887e10', distance_from_sun_km: '15.3999e8', fun_fact: 'Pluto was recently debunked from the official planet list!') - puts venus.summary - puts pluto.summary + # puts venus.summary + # puts pluto.summary + + #instantiate my new solar system named sol + sol_system = SolarSystem.new('Sol') + + # adding planets to sol_sytem with add_planet method in solar_system.rb + sol_system.add_planet(venus) + sol_system.add_planet(pluto) + + list = sol_system.list_planets + puts list + + find_planet = sol_system.find_planet_by_name('venus') + find_planet_2 = sol_system.find_planet_by_name('pluto') + + p find_planet.name + p find_planet_2.summary end main \ No newline at end of file diff --git a/planet.rb b/planet.rb index fe72f7ee..b5923d6f 100644 --- a/planet.rb +++ b/planet.rb @@ -23,3 +23,4 @@ def summary # instantiate each planet here: earth = Planet.new(name: "Earth", color: 'blue-green', mass_kg: '5.972e24', distance_from_sun_km: '1.496e8', fun_fact: 'Only planet known to support life') +earth.name \ No newline at end of file diff --git a/solar_system.rb b/solar_system.rb index e69de29b..297cc534 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -0,0 +1,37 @@ +require_relative 'planet' + +class SolarSystem + #helper method to create readable but not re-writable instance variable. specified using symbols + attr_reader :star_name, :planets + + # constructor method + def initialize star_name + @star_name = star_name + @planets = [] + end + + def add_planet planet + @planets << planet + end + + def list_planets + intro = "Planets orbiting #{star_name}\n" + n = 0 + listing = @planets.map do |planet| + "#{n+=1}. #{planet.name}" + end + return intro, listing + end + + def find_planet_by_name name_query + search_name = name_query.downcase + planets.each do |element| + if element.name.downcase.include?(search_name) + return element + else + return "This planet doesn't exist in our solar system!" + end + end + end + +end \ No newline at end of file From 5da16c7b0beb7aa88c9f7af4542af5240e83c2fc Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Mon, 25 Feb 2019 17:02:15 -0800 Subject: [PATCH 07/15] "terminal table added, find_planet working" --- main.rb | 15 +++++++++------ planet.rb | 12 ++++++------ solar_system.rb | 17 +++++++++++------ 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/main.rb b/main.rb index 7a1e824e..37f43de5 100644 --- a/main.rb +++ b/main.rb @@ -5,10 +5,14 @@ def main #... do stuff with planets... venus = Planet.new(name: "Venus", color: 'purple', mass_kg: '3.88e10', distance_from_sun_km: '1.3e8', fun_fact: 'this planet is commonly associated with feminine energy.') + earth = Planet.new(name: "Earth", color: 'blue-green', mass_kg: '5.972e24', distance_from_sun_km: '1.496e8', fun_fact: 'Only planet known to support life') + pluto = Planet.new(name: "Pluto", color: 'icy-grey', mass_kg: '0.887e10', distance_from_sun_km: '15.3999e8', fun_fact: 'Pluto was recently debunked from the official planet list!') - # puts venus.summary - # puts pluto.summary + # pluto_2 = Planet.new(name: "Pluto", color: 'icy-grey', mass_kg: '0.887e10', distance_from_sun_km: '15.3999e8', fun_fact: 'Pluto recently was debunked from the official planet list!') + + puts venus.summary + puts pluto.summary #instantiate my new solar system named sol sol_system = SolarSystem.new('Sol') @@ -16,15 +20,14 @@ def main # adding planets to sol_sytem with add_planet method in solar_system.rb sol_system.add_planet(venus) sol_system.add_planet(pluto) + # sol_system.add_planet(pluto_2) list = sol_system.list_planets puts list - find_planet = sol_system.find_planet_by_name('venus') - find_planet_2 = sol_system.find_planet_by_name('pluto') + # find_planet = sol_system.find_planet_by_name('pluto') - p find_planet.name - p find_planet_2.summary + # find_planet.each { |name| puts name.summary } end main \ No newline at end of file diff --git a/planet.rb b/planet.rb index b5923d6f..c976990b 100644 --- a/planet.rb +++ b/planet.rb @@ -1,6 +1,7 @@ # wave 1 require 'pry' require 'colorize' +require 'terminal-table' class Planet attr_reader :name, :color, :mass_kg, :distance_from_sun_km, :fun_fact @@ -16,11 +17,10 @@ def initialize (name: "Planet", color: "Color", mass_kg: "Mass in Kg", distance_ end def summary - return "The planet #{self.name} is #{self.color} in color, has a mass of #{self.mass_kg}kg, and is #{self.distance_from_sun_km}km from the sun. A fun fact about your planet: #{self.fun_fact}" + table = Terminal::Table.new :headings => ['name', 'color', 'mass', 'distance', 'fun fact'] + table.add_row [@name, @color, @mass_kg, @distance_from_sun_km, @fun_fact] + + return table + # return "The planet #{self.name} is #{self.color} in color, has a mass of #{self.mass_kg}kg, and is #{self.distance_from_sun_km}km from the sun. A fun fact about your planet: #{self.fun_fact}" end end - -# instantiate each planet here: -earth = Planet.new(name: "Earth", color: 'blue-green', mass_kg: '5.972e24', distance_from_sun_km: '1.496e8', fun_fact: 'Only planet known to support life') - -earth.name \ No newline at end of file diff --git a/solar_system.rb b/solar_system.rb index 297cc534..c5135918 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -24,14 +24,19 @@ def list_planets end def find_planet_by_name name_query - search_name = name_query.downcase + not_found = false + query = [] planets.each do |element| - if element.name.downcase.include?(search_name) - return element - else - return "This planet doesn't exist in our solar system!" + if element.name.downcase == name_query.downcase + not_found = true + query << element end end - end + if !not_found + raise ArgumentError, "This planet ain't here!" + end + + return query + end end \ No newline at end of file From 3e140b6178ca308cef39bc71236aa1e7ead1ca7b Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Mon, 25 Feb 2019 17:24:18 -0800 Subject: [PATCH 08/15] "changing main to control loop" --- main.rb | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/main.rb b/main.rb index 37f43de5..b358a60d 100644 --- a/main.rb +++ b/main.rb @@ -2,17 +2,13 @@ require_relative 'solar_system' def main - #... do stuff with planets... + #... making default planets in list... venus = Planet.new(name: "Venus", color: 'purple', mass_kg: '3.88e10', distance_from_sun_km: '1.3e8', fun_fact: 'this planet is commonly associated with feminine energy.') earth = Planet.new(name: "Earth", color: 'blue-green', mass_kg: '5.972e24', distance_from_sun_km: '1.496e8', fun_fact: 'Only planet known to support life') pluto = Planet.new(name: "Pluto", color: 'icy-grey', mass_kg: '0.887e10', distance_from_sun_km: '15.3999e8', fun_fact: 'Pluto was recently debunked from the official planet list!') - # pluto_2 = Planet.new(name: "Pluto", color: 'icy-grey', mass_kg: '0.887e10', distance_from_sun_km: '15.3999e8', fun_fact: 'Pluto recently was debunked from the official planet list!') - - puts venus.summary - puts pluto.summary #instantiate my new solar system named sol sol_system = SolarSystem.new('Sol') @@ -20,14 +16,30 @@ def main # adding planets to sol_sytem with add_planet method in solar_system.rb sol_system.add_planet(venus) sol_system.add_planet(pluto) - # sol_system.add_planet(pluto_2) + sol_system.add_planet(earth) list = sol_system.list_planets + + learn = true + + while true + puts "Hello and welcome to the \'#{sol_system.star_name}\' solar system." + puts list - # find_planet = sol_system.find_planet_by_name('pluto') + puts "If you would like to see a list of planets enter \'list\' or \'l\'." + + puts "If you would like to learn more about a planet" - # find_planet.each { |name| puts name.summary } + puts list + + puts "What planet would you like to learn more about?" + + end end -main \ No newline at end of file +main + +# user_input = gets.chomp + # find_planet = sol_system.find_planet_by_name('pluto') + # find_planet.each { |name| puts name.summary } \ No newline at end of file From 3bc8cca171d86cdc63cfdc134f2c0e1a06f39f6a Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Mon, 25 Feb 2019 18:04:38 -0800 Subject: [PATCH 09/15] "additions to control loop to print summary of planet" --- main.rb | 35 ++++++++++++++++++----------------- solar_system.rb | 3 ++- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/main.rb b/main.rb index b358a60d..d32404db 100644 --- a/main.rb +++ b/main.rb @@ -12,7 +12,7 @@ def main #instantiate my new solar system named sol sol_system = SolarSystem.new('Sol') - + # adding planets to sol_sytem with add_planet method in solar_system.rb sol_system.add_planet(venus) sol_system.add_planet(pluto) @@ -22,24 +22,25 @@ def main learn = true - while true - puts "Hello and welcome to the \'#{sol_system.star_name}\' solar system." - - puts list - - puts "If you would like to see a list of planets enter \'list\' or \'l\'." - - puts "If you would like to learn more about a planet" - - puts list - - puts "What planet would you like to learn more about?" - + while learn + + puts "Hello and welcome to the \'#{sol_system.star_name}\' solar system." + + puts "If you would like to see a list of planets enter \'list\' or \'l\'. If you would like to learn more about a planet enter enter it's name from the list of planets. If you want to abort the mission enter: exit or quit." + planet_ask = gets.chomp + + if ["list", "l"].include?(planet_ask) + puts list + elsif ["earth", "venus", "pluto"].include?(planet_ask) + find_planet = sol_system.find_planet_by_name(planet_ask) + puts find_planet.each { |name| puts name.summary} + end + # puts planet_ask + # end + learn = false end + end main -# user_input = gets.chomp - # find_planet = sol_system.find_planet_by_name('pluto') - # find_planet.each { |name| puts name.summary } \ No newline at end of file diff --git a/solar_system.rb b/solar_system.rb index c5135918..16b9e0fc 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -39,4 +39,5 @@ def find_planet_by_name name_query return query end -end \ No newline at end of file +end + From a4f1c44fa1c7fb81d1b4e481ba9a9489a09306d1 Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Mon, 25 Feb 2019 21:08:10 -0800 Subject: [PATCH 10/15] "control loop added planet formation and exit loop" --- main.rb | 37 ++++++++++++++++++++++++++++--------- solar_system.rb | 5 ++--- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/main.rb b/main.rb index d32404db..75183629 100644 --- a/main.rb +++ b/main.rb @@ -22,25 +22,44 @@ def main learn = true + + print "Hello and welcome to the \'#{sol_system.star_name}\' solar system." while learn - - puts "Hello and welcome to the \'#{sol_system.star_name}\' solar system." - - puts "If you would like to see a list of planets enter \'list\' or \'l\'. If you would like to learn more about a planet enter enter it's name from the list of planets. If you want to abort the mission enter: exit or quit." - planet_ask = gets.chomp + puts "\n + - If you would like to see a list of planets enter \'list\' or \'l\'. + - If you would like to learn more about an existing planet, enter enter it's name from the list of planets. + - If you would like to create a planet, enter 'generate'. + - Finally if you want to abort the mission enter: exit or quit." + print "Input here: " + planet_ask = gets.chomp.downcase if ["list", "l"].include?(planet_ask) puts list elsif ["earth", "venus", "pluto"].include?(planet_ask) find_planet = sol_system.find_planet_by_name(planet_ask) - puts find_planet.each { |name| puts name.summary} + puts find_planet[0].summary + elsif planet_ask == 'generate' + puts "Please enter the details of your new planet: " + print "Name: " + new_name = gets.chomp + print "Color: " + new_color = gets.chomp + print "Mass in kg: " + mass = gets.chomp + print "Distance from #{sol_system.star_name}: " + distance = gets.chomp + print "Cool facts about your planet: " + fun_deets = gets.chomp + new_planet = Planet.new(name: new_name, color: new_color, mass_kg: mass, distance_from_sun_km: distance, fun_fact: fun_deets ) + sol_system.add_planet(new_planet) + else + puts "mission aborted!!" end - # puts planet_ask - # end learn = false end - end main +#need to figure out why it is printing the planet instance id when puts find_planet + diff --git a/solar_system.rb b/solar_system.rb index 16b9e0fc..18de412f 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -37,7 +37,6 @@ def find_planet_by_name name_query raise ArgumentError, "This planet ain't here!" end - return query + return query #an array of elements... end -end - +end \ No newline at end of file From 6e4895850c4ebb28aa29e536cffa3d0a7abc3757 Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Tue, 26 Feb 2019 10:22:39 -0800 Subject: [PATCH 11/15] "control loop works better..." --- main.rb | 69 ++++++++++++++++++++++++++++--------------------- solar_system.rb | 3 +-- 2 files changed, 40 insertions(+), 32 deletions(-) diff --git a/main.rb b/main.rb index 75183629..f50488c2 100644 --- a/main.rb +++ b/main.rb @@ -20,46 +20,55 @@ def main list = sol_system.list_planets - learn = true - - print "Hello and welcome to the \'#{sol_system.star_name}\' solar system." - while learn - puts "\n + puts "\n - If you would like to see a list of planets enter \'list\' or \'l\'. - If you would like to learn more about an existing planet, enter enter it's name from the list of planets. - If you would like to create a planet, enter 'generate'. - - Finally if you want to abort the mission enter: exit or quit." + - Finally at any point if you want to abort the mission enter: exit or quit." + + running = true + while running print "Input here: " planet_ask = gets.chomp.downcase - - if ["list", "l"].include?(planet_ask) - puts list - elsif ["earth", "venus", "pluto"].include?(planet_ask) - find_planet = sol_system.find_planet_by_name(planet_ask) - puts find_planet[0].summary - elsif planet_ask == 'generate' - puts "Please enter the details of your new planet: " - print "Name: " - new_name = gets.chomp - print "Color: " - new_color = gets.chomp - print "Mass in kg: " - mass = gets.chomp - print "Distance from #{sol_system.star_name}: " - distance = gets.chomp - print "Cool facts about your planet: " - fun_deets = gets.chomp - new_planet = Planet.new(name: new_name, color: new_color, mass_kg: mass, distance_from_sun_km: distance, fun_fact: fun_deets ) - sol_system.add_planet(new_planet) + #currently will only print out last valuse + if running + if ["list", "l"].include?(planet_ask) + puts "Planets orbiting #{sol_system.star_name}\n" + puts list + elsif ["earth", "venus", "pluto"].include?(planet_ask) + find_planet = sol_system.find_planet_by_name(planet_ask) + puts find_planet[0].summary + elsif planet_ask == 'generate' + puts "Please enter the details of your new planet: " + print "Name: " + new_name = gets.chomp + print "Color: " + new_color = gets.chomp + print "Mass in kg: " + mass = gets.chomp + print "Distance from #{sol_system.star_name}: " + distance = gets.chomp + print "Cool facts about your planet: " + fun_deets = gets.chomp + new_planet = Planet.new(name: new_name, color: new_color, mass_kg: mass, distance_from_sun_km: distance, fun_fact: fun_deets ) + sol_system.add_planet(new_planet) + p new_planet + elsif ['exit', 'quit', 'n'].include?(planet_ask) + puts "mission aborted!" + running = false + end + end + + puts "Would you like to perform another inquiry? enter y/n" + question = gets.chomp + if question == 'y' + running = true else - puts "mission aborted!!" + running = false end - learn = false end end main -#need to figure out why it is printing the planet instance id when puts find_planet - diff --git a/solar_system.rb b/solar_system.rb index 18de412f..1e9dadbd 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -15,12 +15,11 @@ def add_planet planet end def list_planets - intro = "Planets orbiting #{star_name}\n" n = 0 listing = @planets.map do |planet| "#{n+=1}. #{planet.name}" end - return intro, listing + return listing end def find_planet_by_name name_query From 96644122dbc065269db30569e0541e00bf007a86 Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Tue, 26 Feb 2019 12:03:16 -0800 Subject: [PATCH 12/15] "moved list_planets option to inside while loop" --- .vscode/launch.json | 15 +++++++++++++++ main.rb | 15 +++++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..c8c516c2 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Debug Local File", + "type": "Ruby", + "request": "launch", + "cwd": "${workspaceRoot}", + "program": "${file}" + } + ] +} \ No newline at end of file diff --git a/main.rb b/main.rb index f50488c2..60778e93 100644 --- a/main.rb +++ b/main.rb @@ -1,5 +1,6 @@ require_relative 'planet' require_relative 'solar_system' +require 'pry' def main #... making default planets in list... @@ -17,9 +18,10 @@ def main sol_system.add_planet(venus) sol_system.add_planet(pluto) sol_system.add_planet(earth) - + list = sol_system.list_planets + print "Hello and welcome to the \'#{sol_system.star_name}\' solar system." puts "\n - If you would like to see a list of planets enter \'list\' or \'l\'. @@ -33,12 +35,12 @@ def main planet_ask = gets.chomp.downcase #currently will only print out last valuse if running - if ["list", "l"].include?(planet_ask) - puts "Planets orbiting #{sol_system.star_name}\n" - puts list - elsif ["earth", "venus", "pluto"].include?(planet_ask) + if ["earth", "venus", "pluto"].include?(planet_ask) find_planet = sol_system.find_planet_by_name(planet_ask) puts find_planet[0].summary + elsif ["list", "l"].include?(planet_ask) + puts "Planets orbiting #{sol_system.star_name}\n" + puts sol_system.list_planets elsif planet_ask == 'generate' puts "Please enter the details of your new planet: " print "Name: " @@ -53,7 +55,7 @@ def main fun_deets = gets.chomp new_planet = Planet.new(name: new_name, color: new_color, mass_kg: mass, distance_from_sun_km: distance, fun_fact: fun_deets ) sol_system.add_planet(new_planet) - p new_planet + puts "#{new_planet.name} has been added to Sol system" elsif ['exit', 'quit', 'n'].include?(planet_ask) puts "mission aborted!" running = false @@ -67,6 +69,7 @@ def main else running = false end + sol_system.add_planet(new_planet) end end From ea429831f3f56d9751d4aa036e8f9a23b0e75539 Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Tue, 26 Feb 2019 13:38:03 -0800 Subject: [PATCH 13/15] "trying to use awesome print, added table with options to remind user" --- main.rb | 45 +++++++++++++++++++++------------------------ solar_system.rb | 19 ++++++++++++++++++- 2 files changed, 39 insertions(+), 25 deletions(-) diff --git a/main.rb b/main.rb index 60778e93..a2ff3e5e 100644 --- a/main.rb +++ b/main.rb @@ -1,6 +1,8 @@ require_relative 'planet' require_relative 'solar_system' -require 'pry' +require 'awesome_print' + + def main #... making default planets in list... @@ -19,18 +21,26 @@ def main sol_system.add_planet(pluto) sol_system.add_planet(earth) - list = sol_system.list_planets - + # list = sol_system.list_planets + print "Hello and welcome to the \'#{sol_system.star_name}\' solar system." puts "\n - If you would like to see a list of planets enter \'list\' or \'l\'. - If you would like to learn more about an existing planet, enter enter it's name from the list of planets. - - If you would like to create a planet, enter 'generate'. + - If you would like to create a planet, enter 'generate', or 'add'. - Finally at any point if you want to abort the mission enter: exit or quit." running = true + loop_count = 0 + while running + if loop_count > 0 + t = Terminal::Table.new + puts "Your options are:" + t << ["enter a planet's name", "list", "l", "add", "generate", "exit", "quit"] + puts t + end print "Input here: " planet_ask = gets.chomp.downcase #currently will only print out last valuse @@ -39,29 +49,17 @@ def main find_planet = sol_system.find_planet_by_name(planet_ask) puts find_planet[0].summary elsif ["list", "l"].include?(planet_ask) - puts "Planets orbiting #{sol_system.star_name}\n" - puts sol_system.list_planets - elsif planet_ask == 'generate' - puts "Please enter the details of your new planet: " - print "Name: " - new_name = gets.chomp - print "Color: " - new_color = gets.chomp - print "Mass in kg: " - mass = gets.chomp - print "Distance from #{sol_system.star_name}: " - distance = gets.chomp - print "Cool facts about your planet: " - fun_deets = gets.chomp - new_planet = Planet.new(name: new_name, color: new_color, mass_kg: mass, distance_from_sun_km: distance, fun_fact: fun_deets ) - sol_system.add_planet(new_planet) - puts "#{new_planet.name} has been added to Sol system" + puts "Planets orbiting #{sol_system.star_name}" + i = 0 + sol_system.list_planets.each { |n| ap "#{i+=1} #{n.name}" } + elsif planet_ask == 'generate' || planet == 'add' + sol_system.user_adds_planet elsif ['exit', 'quit', 'n'].include?(planet_ask) puts "mission aborted!" - running = false + break end end - + loop_count += 1 puts "Would you like to perform another inquiry? enter y/n" question = gets.chomp if question == 'y' @@ -69,7 +67,6 @@ def main else running = false end - sol_system.add_planet(new_planet) end end diff --git a/solar_system.rb b/solar_system.rb index 1e9dadbd..981318e1 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -16,11 +16,28 @@ def add_planet planet def list_planets n = 0 - listing = @planets.map do |planet| + listing = @planets.each do |planet| "#{n+=1}. #{planet.name}" end return listing end + + def user_adds_planet + puts "Please enter the details of your new planet: " + print "Name: " + new_name = gets.chomp + print "Color: " + new_color = gets.chomp + print "Mass in kg: " + mass = gets.chomp + print "Distance from #{star_name}: " + distance = gets.chomp + print "Cool facts about your planet: " + fun_deets = gets.chomp + new_planet = Planet.new(name: new_name, color: new_color, mass_kg: mass, distance_from_sun_km: distance, fun_fact: fun_deets ) + add_planet(new_planet) + puts "#{new_planet.name} has been added to Sol system" + end def find_planet_by_name name_query not_found = false From 603808c6d00f07d802509282e12e65d01064e181 Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Wed, 27 Feb 2019 07:27:22 -0800 Subject: [PATCH 14/15] "corrected some bugs in control loop for outputting summary of planets" --- main.rb | 29 ++++++++++++++++++++++------- planet.rb | 2 +- solar_system.rb | 46 ++++++++++++++++++++-------------------------- 3 files changed, 43 insertions(+), 34 deletions(-) diff --git a/main.rb b/main.rb index a2ff3e5e..cd355837 100644 --- a/main.rb +++ b/main.rb @@ -27,32 +27,47 @@ def main print "Hello and welcome to the \'#{sol_system.star_name}\' solar system." puts "\n - If you would like to see a list of planets enter \'list\' or \'l\'. - - If you would like to learn more about an existing planet, enter enter it's name from the list of planets. + - If you would like to learn more about an existing planet, enter 'summary'. - If you would like to create a planet, enter 'generate', or 'add'. - Finally at any point if you want to abort the mission enter: exit or quit." running = true loop_count = 0 + + # planet_ask = "earth" + # i = 0 + # while i < sol_system.list_planets.length + # if sol_system.list_planets[i].name == planet ask + # puts sol_system.list_planets[i].name + # end + # i += 1 + # # end + + # find_planet = sol_system.find_planet_by_name(planet_ask) + # puts find_planet[0].summary + # end while running if loop_count > 0 t = Terminal::Table.new puts "Your options are:" - t << ["enter a planet's name", "list", "l", "add", "generate", "exit", "quit"] + t << ["summary", "list", "l", "add", "generate", "exit", "quit"] puts t end print "Input here: " planet_ask = gets.chomp.downcase #currently will only print out last valuse if running - if ["earth", "venus", "pluto"].include?(planet_ask) - find_planet = sol_system.find_planet_by_name(planet_ask) - puts find_planet[0].summary + if planet_ask == 'summary' + puts "Enter name of planet" + planet_name = gets.chomp.downcase + find_planet = sol_system.find_planet_by_name(planet_name) + puts find_planet.summary elsif ["list", "l"].include?(planet_ask) puts "Planets orbiting #{sol_system.star_name}" i = 0 - sol_system.list_planets.each { |n| ap "#{i+=1} #{n.name}" } - elsif planet_ask == 'generate' || planet == 'add' + sol_system.list_planets.each { |n| ap "#{i+=1}. #{n.name}" } + elsif planet_ask == 'generate' || planet_ask == 'add' sol_system.user_adds_planet elsif ['exit', 'quit', 'n'].include?(planet_ask) puts "mission aborted!" diff --git a/planet.rb b/planet.rb index c976990b..715db312 100644 --- a/planet.rb +++ b/planet.rb @@ -17,7 +17,7 @@ def initialize (name: "Planet", color: "Color", mass_kg: "Mass in Kg", distance_ end def summary - table = Terminal::Table.new :headings => ['name', 'color', 'mass', 'distance', 'fun fact'] + table = Terminal::Table.new :headings => ['Name', 'Color', 'Mass', 'Distance', 'Fun fact'] table.add_row [@name, @color, @mass_kg, @distance_from_sun_km, @fun_fact] return table diff --git a/solar_system.rb b/solar_system.rb index 981318e1..88479e18 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -24,35 +24,29 @@ def list_planets def user_adds_planet puts "Please enter the details of your new planet: " - print "Name: " - new_name = gets.chomp - print "Color: " - new_color = gets.chomp - print "Mass in kg: " - mass = gets.chomp - print "Distance from #{star_name}: " - distance = gets.chomp - print "Cool facts about your planet: " - fun_deets = gets.chomp - new_planet = Planet.new(name: new_name, color: new_color, mass_kg: mass, distance_from_sun_km: distance, fun_fact: fun_deets ) - add_planet(new_planet) - puts "#{new_planet.name} has been added to Sol system" + print "Name: " + new_name = gets.chomp.downcase + print "Color: " + new_color = gets.chomp + print "Mass in kg: " + mass = gets.chomp + print "Distance from #{star_name}: " + distance = gets.chomp + print "Cool facts about your planet: " + fun_deets = gets.chomp + new_planet = Planet.new(name: new_name, color: new_color, mass_kg: mass, distance_from_sun_km: distance, fun_fact: fun_deets ) + add_planet(new_planet) + puts "#{new_planet.name} has been added to Sol system" + return new_planet end def find_planet_by_name name_query not_found = false - query = [] - planets.each do |element| - if element.name.downcase == name_query.downcase - not_found = true - query << element - end - end - - if !not_found - raise ArgumentError, "This planet ain't here!" - end - - return query #an array of elements... + + query = @planets.find { |element| element.name.downcase == name_query.downcase } + # if !not_found + # raise ArgumentError, "This planet ain't here!" + # end + return query #an array of elements... end end \ No newline at end of file From d49ef605cd564f750f735f8c1aace442fbcb95e7 Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Wed, 27 Feb 2019 07:28:43 -0800 Subject: [PATCH 15/15] "used rufo to adjust any style mistakes" --- main.rb | 45 ++++++++++++++++++--------------------- planet.rb | 14 ++++++------- solar_system.rb | 56 ++++++++++++++++++++++++------------------------- 3 files changed, 55 insertions(+), 60 deletions(-) diff --git a/main.rb b/main.rb index cd355837..75a5d07a 100644 --- a/main.rb +++ b/main.rb @@ -1,28 +1,24 @@ -require_relative 'planet' -require_relative 'solar_system' -require 'awesome_print' - - +require_relative "planet" +require_relative "solar_system" +require "awesome_print" def main #... making default planets in list... - venus = Planet.new(name: "Venus", color: 'purple', mass_kg: '3.88e10', distance_from_sun_km: '1.3e8', fun_fact: 'this planet is commonly associated with feminine energy.') + venus = Planet.new(name: "Venus", color: "purple", mass_kg: "3.88e10", distance_from_sun_km: "1.3e8", fun_fact: "this planet is commonly associated with feminine energy.") - earth = Planet.new(name: "Earth", color: 'blue-green', mass_kg: '5.972e24', distance_from_sun_km: '1.496e8', fun_fact: 'Only planet known to support life') - - pluto = Planet.new(name: "Pluto", color: 'icy-grey', mass_kg: '0.887e10', distance_from_sun_km: '15.3999e8', fun_fact: 'Pluto was recently debunked from the official planet list!') + earth = Planet.new(name: "Earth", color: "blue-green", mass_kg: "5.972e24", distance_from_sun_km: "1.496e8", fun_fact: "Only planet known to support life") + pluto = Planet.new(name: "Pluto", color: "icy-grey", mass_kg: "0.887e10", distance_from_sun_km: "15.3999e8", fun_fact: "Pluto was recently debunked from the official planet list!") #instantiate my new solar system named sol - sol_system = SolarSystem.new('Sol') - + sol_system = SolarSystem.new("Sol") + # adding planets to sol_sytem with add_planet method in solar_system.rb - sol_system.add_planet(venus) + sol_system.add_planet(venus) sol_system.add_planet(pluto) sol_system.add_planet(earth) - + # list = sol_system.list_planets - print "Hello and welcome to the \'#{sol_system.star_name}\' solar system." puts "\n @@ -30,14 +26,14 @@ def main - If you would like to learn more about an existing planet, enter 'summary'. - If you would like to create a planet, enter 'generate', or 'add'. - Finally at any point if you want to abort the mission enter: exit or quit." - + running = true loop_count = 0 # planet_ask = "earth" # i = 0 - # while i < sol_system.list_planets.length - # if sol_system.list_planets[i].name == planet ask + # while i < sol_system.list_planets.length + # if sol_system.list_planets[i].name == planet ask # puts sol_system.list_planets[i].name # end # i += 1 @@ -46,7 +42,7 @@ def main # find_planet = sol_system.find_planet_by_name(planet_ask) # puts find_planet[0].summary # end - + while running if loop_count > 0 t = Terminal::Table.new @@ -58,7 +54,7 @@ def main planet_ask = gets.chomp.downcase #currently will only print out last valuse if running - if planet_ask == 'summary' + if planet_ask == "summary" puts "Enter name of planet" planet_name = gets.chomp.downcase find_planet = sol_system.find_planet_by_name(planet_name) @@ -66,18 +62,18 @@ def main elsif ["list", "l"].include?(planet_ask) puts "Planets orbiting #{sol_system.star_name}" i = 0 - sol_system.list_planets.each { |n| ap "#{i+=1}. #{n.name}" } - elsif planet_ask == 'generate' || planet_ask == 'add' + sol_system.list_planets.each { |n| ap "#{i += 1}. #{n.name}" } + elsif planet_ask == "generate" || planet_ask == "add" sol_system.user_adds_planet - elsif ['exit', 'quit', 'n'].include?(planet_ask) + elsif ["exit", "quit", "n"].include?(planet_ask) puts "mission aborted!" break end end loop_count += 1 - puts "Would you like to perform another inquiry? enter y/n" + puts "Would you like to perform another inquiry? enter y/n" question = gets.chomp - if question == 'y' + if question == "y" running = true else running = false @@ -86,4 +82,3 @@ def main end main - diff --git a/planet.rb b/planet.rb index 715db312..1f126bee 100644 --- a/planet.rb +++ b/planet.rb @@ -1,15 +1,15 @@ # wave 1 -require 'pry' -require 'colorize' -require 'terminal-table' +require "pry" +require "colorize" +require "terminal-table" class Planet attr_reader :name, :color, :mass_kg, :distance_from_sun_km, :fun_fact - - def initialize (name: "Planet", color: "Color", mass_kg: "Mass in Kg", distance_from_sun_km: "Distance in km", fun_fact: "This is a fun fact") + + def initialize(name: "Planet", color: "Color", mass_kg: "Mass in Kg", distance_from_sun_km: "Distance in km", fun_fact: "This is a fun fact") @name = name @color = color - @mass_kg = mass_kg + @mass_kg = mass_kg @distance_from_sun_km = distance_from_sun_km @fun_fact = fun_fact @summary = summary @@ -17,7 +17,7 @@ def initialize (name: "Planet", color: "Color", mass_kg: "Mass in Kg", distance_ end def summary - table = Terminal::Table.new :headings => ['Name', 'Color', 'Mass', 'Distance', 'Fun fact'] + table = Terminal::Table.new :headings => ["Name", "Color", "Mass", "Distance", "Fun fact"] table.add_row [@name, @color, @mass_kg, @distance_from_sun_km, @fun_fact] return table diff --git a/solar_system.rb b/solar_system.rb index 88479e18..eb82fcf3 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -1,52 +1,52 @@ -require_relative 'planet' +require_relative "planet" class SolarSystem #helper method to create readable but not re-writable instance variable. specified using symbols - attr_reader :star_name, :planets - + attr_reader :star_name, :planets + # constructor method - def initialize star_name + def initialize(star_name) @star_name = star_name @planets = [] end - def add_planet planet + def add_planet(planet) @planets << planet end def list_planets n = 0 listing = @planets.each do |planet| - "#{n+=1}. #{planet.name}" + "#{n += 1}. #{planet.name}" end return listing end def user_adds_planet puts "Please enter the details of your new planet: " - print "Name: " - new_name = gets.chomp.downcase - print "Color: " - new_color = gets.chomp - print "Mass in kg: " - mass = gets.chomp - print "Distance from #{star_name}: " - distance = gets.chomp - print "Cool facts about your planet: " - fun_deets = gets.chomp - new_planet = Planet.new(name: new_name, color: new_color, mass_kg: mass, distance_from_sun_km: distance, fun_fact: fun_deets ) - add_planet(new_planet) - puts "#{new_planet.name} has been added to Sol system" - return new_planet + print "Name: " + new_name = gets.chomp.downcase + print "Color: " + new_color = gets.chomp + print "Mass in kg: " + mass = gets.chomp + print "Distance from #{star_name}: " + distance = gets.chomp + print "Cool facts about your planet: " + fun_deets = gets.chomp + new_planet = Planet.new(name: new_name, color: new_color, mass_kg: mass, distance_from_sun_km: distance, fun_fact: fun_deets) + add_planet(new_planet) + puts "#{new_planet.name} has been added to Sol system" + return new_planet end - - def find_planet_by_name name_query + + def find_planet_by_name(name_query) not_found = false - + query = @planets.find { |element| element.name.downcase == name_query.downcase } - # if !not_found - # raise ArgumentError, "This planet ain't here!" - # end - return query #an array of elements... + # if !not_found + # raise ArgumentError, "This planet ain't here!" + # end + return query #an array of elements... end -end \ No newline at end of file +end