-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelocator
executable file
·100 lines (86 loc) · 4.68 KB
/
relocator
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env ruby
require 'highline/import'
require 'colorize'
require_relative 'lib/environment'
require_relative 'lib/ascii'
$color_dark = :black
$color_light = :light_yellow
def add_location
location_options = {}
location_options[:city] = ask("What is the name of the city or town you wish to add?".bold.colorize(:color => $color_dark, :background => $color_light)) { |q| q.default = "none" }
location_options[:city].capitalize!
states = ["AL","AK","AZ","AR","CA","CO","CT","DE","FL","GA","HI","ID","IL","IN","IA","KS","KY","LA","ME","MD","MA","MI","MN","MS","MO","MT","NE","NV","NH","NJ","NM","NY","NC","ND","OH","OK","OR","PA","RI","SC","SD","TN","TX","UT","VT","VA","WA","WV","WI","WY","AS","DC","FM","GU","MH","MP","PW","PR","VI","AE","AA","AP"]
location_options[:state_code] = ask("What state is #{location_options[:city]} in?".bold.colorize(:color => $color_dark, :background => $color_light)) { |q| q.in = (states << states.map{|state| state.downcase}).flatten }
location_options[:state_code].upcase!
choose do |menu|
menu.prompt = "What climate does #{location_options[:city]} have?".bold.colorize(:color => $color_dark, :background => $color_light)
menu.choice("Cool") do |chosen|
location_options[:climate] = 'Cool'
end
menu.choice("Temperate") do |chosen|
location_options[:climate] = 'Temperate'
end
menu.choice("Warm") do |chosen|
location_options[:climate] = 'Warm'
end
end
location_options[:employment_outlook] = ask("What employment possibilities exist in #{location_options[:city]}?".bold.colorize(:color => $color_dark, :background => $color_light)) { |q| q.default = "none" }
location_options[:cost_of_living] = ask("How would you rate the cost of living of #{location_options[:city]}? (1-100)".bold.colorize(:color => $color_dark, :background => $color_light), Integer) { |q| q.in = 1..100}
location_options[:cost_of_living] = location_options[:cost_of_living].to_i
location_options[:notes] = ask("Any other information you'd like to add about #{location_options[:city]}?".bold.colorize(:color => $color_dark, :background => $color_light)) { |q| q.default = "none" }
if Location.where(city: location_options[:city].capitalize, state_code: location_options[:state_code].upcase) != []
puts "Sorry, that location already exists.".colorize(:color => $color_dark, :background => $color_light)
else
Location.create(location_options)
puts "Location added".bold.colorize(:color => $color_light, :background => $color_dark)
end
end
environment = ARGV[0]
Environment.environment = environment || "production"
Environment.connect_to_database
Ascii.welcome
loop do
Ascii.menu
choose do |menu|
menu.prompt = "What would you like to do?".bold.colorize(:color => $color_dark, :background => $color_light)
menu.choice("Add") do |chosen|
add_location
end
menu.choice("View") do |chosen|
choose do |menu|
menu.prompt = "Would you like to filter your results?".bold.colorize(:color => $color_dark, :background => $color_light)
menu.choice("Yes") do |chosen|
locations = Location.build_search
locations.each do |location|
puts [location.city, location.state_code, location.climate, location.employment_outlook, location.cost_of_living, location.notes].inspect.bold.colorize(:color => $color_light, :background => $color_dark)
end
end
menu.choice("No") do |chosen|
search_city = Location.fetch_query('view')
puts '[ID, CITY, STATE, CLIMATE, EMPLOYMENT OUTLOOK, COST OF LIVING INDEX, NOTES]'.bold.colorize(:color => $color_light, :background => $color_dark)
locations = Location.locate(search_city)
locations.each do |location|
puts [location.city, location.state_code, location.climate, location.employment_outlook, location.cost_of_living, location.notes].inspect.bold.colorize(:color => $color_light, :background => $color_dark)
end
puts ""
end
end
end
menu.choice("Edit") do |chosen|
old_update_city = Location.fetch_query('update')
new_update_city = Location.fetch_replacement(old_update_city)
puts "Old Location: #{old_update_city.inspect}".colorize(:color => $color_light, :background => $color_dark)
puts "Updated Location: #{new_update_city.inspect}".colorize(:color => $color_dark, :background => $color_light)
puts 'Location Updated'.bold.colorize(:color => $color_light, :background => $color_dark)
end
menu.choice("Remove") do |chosen|
delete_city = Location.fetch_query('remove')
puts delete_city
Location.remove(delete_city)
end
menu.choice("EXIT") do |chosen|
Ascii.goodbye
exit
end
end
end