forked from AdaGold/solar-system
-
Notifications
You must be signed in to change notification settings - Fork 48
Sockets - Tatiana #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tatsqui
wants to merge
15
commits into
Ada-C11:master
Choose a base branch
from
tatsqui:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
787c784
created solar_sytem.rb
tatsqui a9ac58f
"wrong file name, mv planet.rb"
tatsqui c4f8b96
added main and wrote Planet Class
tatsqui 412cae8
"created two new instances of planet in main"
tatsqui 3372227
"wave 2 - created solar_sytem.rb"
tatsqui d777f87
"created add_method, list_planets, and find_planet methods"
tatsqui 5da16c7
"terminal table added, find_planet working"
tatsqui 3e140b6
"changing main to control loop"
tatsqui 3bc8cca
"additions to control loop to print summary of planet"
tatsqui a4f1c44
"control loop added planet formation and exit loop"
tatsqui 6e48958
"control loop works better..."
tatsqui 9664412
"moved list_planets option to inside while loop"
tatsqui ea42983
"trying to use awesome print, added table with options to remind user"
tatsqui 603808c
"corrected some bugs in control loop for outputting summary of planets"
tatsqui d49ef60
"used rufo to adjust any style mistakes"
tatsqui File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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}" | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| 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.") | ||
|
|
||
| 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") | ||
|
|
||
| # 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(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\'. | ||
| - 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 << ["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 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_ask == "add" | ||
| sol_system.user_adds_planet | ||
| 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" | ||
| question = gets.chomp | ||
| if question == "y" | ||
| running = true | ||
| else | ||
| running = false | ||
| end | ||
| end | ||
| end | ||
|
|
||
| main | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # wave 1 | ||
| 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") | ||
| @name = name | ||
| @color = color | ||
| @mass_kg = mass_kg | ||
| @distance_from_sun_km = distance_from_sun_km | ||
| @fun_fact = fun_fact | ||
| @summary = summary | ||
| return summary | ||
| end | ||
|
|
||
| def summary | ||
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| 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 | ||
| n = 0 | ||
| 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.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) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This information gathering, seeing as it is coming from the user and talking to the user, generally makes more sense as a part of main to me. |
||
| 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.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 | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like this! You gave me a quit option already, and if I want it, I'll use it!