Class: Cli

Inherits:
Object
  • Object
show all
Defined in:
lib/FreeWiFiNYC/cli.rb

Class Method Summary collapse

Class Method Details

.borough_assignerObject



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/FreeWiFiNYC/cli.rb', line 83

def self.borough_assigner
  borough = gets.chomp.upcase
  case borough
    when "1"
      puts "Bronx"
      @borough = "Bronx"
      Api.neighborhood_list
    when "2"
      puts "Brooklyn"
      @borough = "Brooklyn"
      Api.neighborhood_list
    when "3"
      puts "Manhattan"
      @borough = "Manhattan"
      Api.neighborhood_list
    when "4"
      puts "Queens"
      @borough = "Queens"
      Api.neighborhood_list
    when "5"
      puts "Staten Island"
      @borough = "Staten Island"
      Api.neighborhood_list
    when "EXIT"
      find_wifi
    else
      puts "Invalid entry. Enter a number 1-5 or type 'exit'.\n"
      puts "
      1 - Bronx
      2 - Brooklyn
      3 - Manhattan
      4 - Queens
      5 - Staten Island
      "
      borough_assigner
    end
end

.borough_nameObject



121
122
123
# File 'lib/FreeWiFiNYC/cli.rb', line 121

def self.borough_name
  @borough
end

.borough_selectorObject



70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/FreeWiFiNYC/cli.rb', line 70

def self.borough_selector
  puts "Please select a borough to begin your search."
  puts "
  1 - Bronx
  2 - Brooklyn
  3 - Manhattan
  4 - Queens
  5 - Staten Island
  "
  puts "Enter a number: \n"
  borough_assigner
end

.callObject



5
6
7
8
9
# File 'lib/FreeWiFiNYC/cli.rb', line 5

def self.call
  Scraper.scrape_data
  welcome
  find_wifi
end

.find_wifiObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/FreeWiFiNYC/cli.rb', line 19

def self.find_wifi
  puts "Please enter a zip code or type 'help' to search by neighborhood or type 'exit':"
  @find_wifi_input = gets.chomp.upcase

  if @find_wifi_input == "HELP"
    borough_selector
  # elsif @zip_codes.include?(@find_wifi_input)
  elsif Scraper.zips.include?(@find_wifi_input)
      Api.zip_code
  elsif @find_wifi_input == "EXIT"
    return goodbye
  elsif @find_wifi_input.length != 5
    puts "Invalid entry. Please enter a 5 digit NYC zip code."
    find_wifi
  else
    Scraper.zipcode_hardcode.include?(@find_wifi_input.to_i) ?
    (puts "Sorry there is no free wifi in this area of NYC.\nType 'help' to search by neighborhood.")
    : (puts "Invalid entry. Type 'help' to search by neighborhood.")
    find_wifi
  end
end

.find_wifi_inputObject



41
42
43
# File 'lib/FreeWiFiNYC/cli.rb', line 41

def self.find_wifi_input
  @find_wifi_input
end

.goodbyeObject



15
16
17
# File 'lib/FreeWiFiNYC/cli.rb', line 15

def self.goodbye
  puts "Thanks for using Search Free Wi-Fi NYC. Goodbye!"
end

.helpObject



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/FreeWiFiNYC/cli.rb', line 45

def self.help
  puts "Enter 1 for list of neighborhoods. Enter 2 for list of location types."
  help_num = gets.chomp
    if help_num == "1"
      borough
    elsif help_num == "2"
      location_type
    else
      help
    end
end

.search_again_metObject



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/FreeWiFiNYC/cli.rb', line 57

def self.search_again_met
  puts "\nWould you like to search again? Type 'Yes' or 'No'."
  search_again = gets.chomp.upcase
  if search_again == "YES" || search_again == "Y"
    find_wifi
  elsif search_again == "NO" || search_again == "N"
    return goodbye
  else
    puts "Please type 'Yes' or 'No'."
    search_again_met
  end
end

.welcomeObject



11
12
13
# File 'lib/FreeWiFiNYC/cli.rb', line 11

def self.welcome
  puts "\nHello, I can help you find free Wi-Fi. You can search by zip code or neighborhood.\n"
end