Class: InternetNearMe::CLI

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



4
5
6
# File 'lib/internet_near_me/cli.rb', line 4

def initialize
  @exit = false 
end

Instance Attribute Details

#exitObject

Returns the value of attribute exit.



2
3
4
# File 'lib/internet_near_me/cli.rb', line 2

def exit
  @exit
end

#zip_codeObject

Returns the value of attribute zip_code.



2
3
4
# File 'lib/internet_near_me/cli.rb', line 2

def zip_code
  @zip_code
end

Instance Method Details

#callObject



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/internet_near_me/cli.rb', line 8

def call
  welcome
  loop do
    if !exit
      get_zip_code
      exit ? break : get_more_details(list_internet_cafes)
    else
      break
    end
  end
  goodbye
end

#get_more_details(internet_cafes) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/internet_near_me/cli.rb', line 52

def get_more_details(internet_cafes)
  loop do
    puts "Enter a number to get more details or 'back' to enter a new zip code:"
    input = gets.strip
    if input == 'back'
      break
    elsif input == 'exit'
      @exit = true
      break
    else
      internet_cafe = InternetNearMe::Scraper.new.scrape_details(internet_cafes[input.to_i - 1])
      render_divider
      puts internet_cafe.name
      puts internet_cafe.phone
      puts "Today: #{internet_cafe.hours}"
      puts "#{internet_cafe.rating} (#{internet_cafe.number_of_reviews} reviews)"
      puts internet_cafe.price
      puts internet_cafe.website
      render_divider
    end
  end
end

#get_zip_codeObject



29
30
31
32
33
34
35
36
37
# File 'lib/internet_near_me/cli.rb', line 29

def get_zip_code
  puts "Please enter your zip code:"
  input = gets.strip
  if input == 'exit'
    @exit = true
  else
    @zip_code = input
  end
end

#goodbyeObject



25
26
27
# File 'lib/internet_near_me/cli.rb', line 25

def goodbye
  puts "Goodbye!"
end

#list_internet_cafesObject



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/internet_near_me/cli.rb', line 39

def list_internet_cafes
  puts "Internet cafes near #{zip_code}:"
  internet_cafes = InternetNearMe::Scraper.new.scrape_by_zip_code(zip_code)
  internet_cafes.each.with_index(1) do |internet_cafe, index| 
    render_divider
    puts "#{index}."
    puts internet_cafe.name
    puts internet_cafe.address
  end
  render_divider
  internet_cafes
end

#welcomeObject



21
22
23
# File 'lib/internet_near_me/cli.rb', line 21

def welcome
  puts "Welcome to internet_near_me! Enter 'exit' at any time to exit."
end