Skip to content

Commit 0e816c0

Browse files
committed
Merge branch 'master' of github.com:epoch/wdi5_homework
2 parents 3716357 + c5caae1 commit 0e816c0

File tree

4,004 files changed

+500815
-1120
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

4,004 files changed

+500815
-1120
lines changed

calc.rb

-193
This file was deleted.

hackers/allen_hsu/wk1d4/MTA1.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def stops_on_journey (start_index, stop_index, line_and_station, hash)
4949
end
5050
stops
5151
end
52-
52+
#stops list returns [stops] or [stops, common]
5353
def stops_list(hash, start_station, end_station)
5454
stops =[]
5555
common = hash[start_station[:line]] & hash[end_station[:line]]
@@ -88,6 +88,7 @@ def menu(hash)
8888

8989
puts `clear`
9090
puts "Station Listing at #{journey[point][:line]} Line"
91+
#check if starting is available and remove from list
9192
if !journey['starting'][:line].nil?
9293
journey[point][:station] = options_select(temp = hash[journey[point][:line]].dup.delete_if{|x| x == journey['starting'][:station]})
9394
else

hackers/allen_hsu/wk1d5/animal.rb

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Animal
2+
attr_accessor :name, :species, :age, :gender, :weight, :color, :was_neutered, :toy, :description
3+
def initialize(name = nil, species = nil, age = nil, gender = nil, weight = nil, color = nil, was_neutered = nil, toy = nil, description = nil)
4+
@name = name
5+
@species = species
6+
@age = age
7+
@gender = gender
8+
@weight = weight
9+
@color = color
10+
@was_neutered = was_neutered
11+
@toy = toy
12+
@description = description
13+
end
14+
15+
def to_s
16+
"#{species} \t #{name}"
17+
end
18+
end
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class ArrayToObject
2+
attr_accessor :array
3+
def initialize(array)
4+
@array = array
5+
end
6+
end

hackers/allen_hsu/wk1d5/client.rb

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Client
2+
attr_accessor :name, :num_of_children, :age, :array
3+
def initialize(name = nil, num_of_children = nil, age = nil, array = nil)
4+
@name = name
5+
@num_of_children = num_of_children
6+
@age = age
7+
@array = array
8+
end
9+
10+
def to_s
11+
"#{@name}"
12+
end
13+
end

hackers/allen_hsu/wk1d5/clients.csv

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name,num_of_children,age,array
2+
Walbert,45,3,"[#<Animal:0x00000101118418 @name=""Birdie"", @species=:bird, @age=2, @gender=:male, @weight=3, @color=:blue, @was_neutered=:no, @toy=""Makes alot of noice in the morning"", @description=""XYZ"">]"
3+
HappiTails,0,0,"[#<Animal:0x000001011182b0 @name=""Jack"", @species=:dog, @age=5, @gender=:male, @weight=6, @color=:yellow, @was_neutered=:yes, @toy=""Loves bacon"", @description=""XYZ"">]"

hackers/allen_hsu/wk1d5/csvtest

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require 'csv'

hackers/allen_hsu/wk1d5/csvtest.rb

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
require 'csv'
2+
require 'pry'
3+
require_relative 'client'
4+
5+
client_list = []
6+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require 'csv'
2+
require 'pry'
3+
require_relative 'client'
4+
require_relative 'menupage'
5+
require_relative 'arraytoobject'
6+
require 'yaml'
7+
c1 = Client.new("Walbert", 45, 3, [])
8+
c2 = Client.new("Jeff Morrison", 50, 4, [])
9+
clients = [c1,c2]

hackers/allen_hsu/wk1d5/main.rb

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
require 'pry'
2+
require 'pry-debugger'
3+
require 'csv'
4+
require_relative 'animal.rb'
5+
require_relative 'client.rb'
6+
require_relative 'menupage'
7+
require_relative 'arraytoobject'
8+
#### SEED DATA ####
9+
10+
a1 = Animal.new("Birdie", :bird, 2, :male, 3, :blue, :no, "Makes alot of noice in the morning", "XYZ")
11+
a2 = Animal.new("Jack", :dog, 5, :male, 6, :yellow, :yes, "Loves bacon", "XYZ")
12+
c1 = Client.new("Walbert", 45, 3, [a1])
13+
shelter = Client.new("HappiTails", 0 , 0 , [a2])
14+
$clients = [c1,shelter]
15+
16+
$animals = [a1, a2]
17+
18+
#### Load from CSV ####
19+
#helpers
20+
#call options select object object
21+
def move(owners, object_being_moved, object_destination)
22+
original_owner = nil
23+
owners.each do |owner|
24+
if owner.array.include? object_being_moved
25+
original_owner = owner
26+
object_destination.array << owner.array.delete(object_being_moved)
27+
end
28+
end
29+
puts "#{object_being_moved} moved to #{object_destination} from #{original_owner}"
30+
end
31+
#### Menu ####
32+
33+
client_menu = MenuPage.new(ArrayToObject.new($clients))
34+
animal_menu = MenuPage.new(ArrayToObject.new($animals))
35+
menu_hierarchy = []
36+
#binding.pry
37+
loop do
38+
puts `clear`
39+
puts "HappiTails Database System"
40+
puts '======================================='
41+
puts '1. Client List and Operations'
42+
puts '2. Animal List and Operations'
43+
puts '3. Move animals'
44+
puts '4. Quit and Save'
45+
46+
option = gets.chomp.to_i
47+
case option
48+
when 1
49+
menu_hierarchy << client_menu
50+
loop do
51+
loop do
52+
current_menu_obj = menu_hierarchy[-1]
53+
current_menu_obj.display_options(current_menu_obj.object_array)
54+
current_menu_obj.options_select(current_menu_obj.object_array)
55+
if current_menu_obj.option.class != String
56+
if current_menu_obj.option.methods.include? :array
57+
new_menu_obj = MenuPage.new(current_menu_obj.option)
58+
menu_hierarchy << new_menu_obj
59+
end
60+
end
61+
break if current_menu_obj.option == 'b'
62+
end
63+
menu_hierarchy.pop
64+
break if menu_hierarchy.length == 0
65+
end
66+
when 2
67+
animal_menu.display_options(animal_menu.object_array)
68+
animal_menu.options_select(animal_menu.object_array)
69+
when 3
70+
animal_menu.display_options(animal_menu.object_array)
71+
puts "Choose animal to move"
72+
animal = animal_menu.options_select(animal_menu.object_array)
73+
client_menu.display_options(client_menu.object_array)
74+
puts "Move #{animal} to where?"
75+
client = client_menu.options_select(client_menu.object_array)
76+
move($clients,animal, client)
77+
end
78+
79+
break if option == 4
80+
end
81+
CSV.open('clients.csv','w',
82+
:write_headers=> true,
83+
:headers => ["name","num_of_children","age","array"] #< column header
84+
) do|hdr|
85+
binding.pry
86+
$clients.each do |client|
87+
hdr << [client.name, client.num_of_children, client.age, client.array]
88+
end
89+
end
90+

0 commit comments

Comments
 (0)