-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.rb
69 lines (60 loc) · 2.27 KB
/
controller.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
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
require_relative 'listing'
require_relative 'View_class'
require 'pry'
class Controller
CATEGORY_CODES = [["Aging", "aging"],
["Anti-Discrimination/HR", "anti_discrimination_human_rights"],
["Arts", "anti_discrimination_human_rights"],
["Business", "business"],
["Childcare and parent", "child_care_parent_information"],
["Community Service/Volunteer", "community_service_volunteerism"],
["Counseling", "counseling_support_groups"],
["Disability", " disabilities"],
["Domestic Violence", "domestic_violence"],
["education", "education"],
["Employment", "employment_job_training"],
["Health", "health"],
["Homelessness", "homelessness"],
["Housing", "housing"],
["Immigration", "immigration"],
["Legal Services", "legal_services"],
["LGBT", "lesbian_gay_bisexual_and_or_transgender"],
["Personal Finance", "personal_finance_financial_education"],
["Professional Association", "professional_association"],
["Veterans", "veterans_military_families"],
["Victim Services", "victim_services"],
["Women's Groups", "women_s_groups"],
["Youth Services", "youth_services"]]
BOROUGHS = ["bronx", "brooklyn", "manhattan", "queens", "staten_island"]
attr_reader :viewer
def initialize
@viewer = View.new
run_interface
end
def final_results
@final_results
end
def run_interface
viewer.welcome_message
viewer.category_prompt(CATEGORY_CODES)
user_index_choice = viewer.get_input - 1
check_response_type(user_index_choice)
listing_by_category = build_listing_objects(CATEGORY_CODES[user_index_choice][1])
viewer.borough_prompt(BOROUGHS)
user_burough_choice = viewer.get_input - 1
final_results = find_listings_by_location(listing_by_category, user_burough_choice)
viewer.display_listing(final_results)
end
def build_listing_objects(category_code)
response = open("http://data.cityofnewyork.us/resource/pqg4-dm6b.json?#{category_code}=Y")
JSON.parse(response.read).map { |listing_hash| Listing.new(listing_hash)}
end
def find_listings_by_location(listings_array, borough_number)
listings_array.select { |listing| listing.borough.include?(BOROUGHS[borough_number]) }
end
def check_response_type(arg)
if !(1..23).include?(arg)
print "Please select a number \n"
end
end
end