Class: BestCity::CLI

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

Instance Method Summary collapse

Instance Method Details

#callObject



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

def call
  BestCity::Scraper.new.make_games
  start
end

#show_cities(from_number) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/best_cities/cli.rb', line 80

def show_cities(from_number)
  120.times do print "*" end
  puts ""
  puts "             Cities #{from_number} - #{from_number+9} "
  120.times do print "*" end
  puts ""
  puts "No.            city"
  BestCity::City.all[from_number-1, 10].each.with_index(from_number) do |city, index|
    str = format('%2d', index)
  puts "#{str}.        #{city.rank_city.split(".")[1]}"
  end
  120.times do print "*" end
end

#show_city(city) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/best_cities/cli.rb', line 64

def show_city(city)
  print  %x{clear}
  120.times do print "*" end
  puts "                      #{city.rank_city.upcase} "
  120.times do print "*" end
  puts ""
  puts "Population           #{city.population}"
  puts "Median Annual Salary #{city.median_annual_salary}"
  puts "Quality of life      #{city.quality_of_life}"
  puts "Overall value        #{city.overall_value}"
  puts ""
  puts "#{city.description}"
  120.times do print "*" end
  ##puts "Description:           #{game.description}"
end

#startObject



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
# File 'lib/best_cities/cli.rb', line 8

def start
  print  %x{clear}
  puts "Welcome to the 50 Best cities to live in America 2016"
  puts ""
  puts "What number city would you like to see?"
  puts "a) 1-10"
  puts "b) 11-20 "
  puts "c) 21-30"
  puts "d) 31-40 "
  puts "e) 41-50"
  puts "Enter the alphabet"
  input= ' '
  while !['a','b','c','d','e'].include?(input) do
   input = gets.strip
  end
  i=1
  case input
  when 'a'
    i=1
  when 'b'
    i=11
  when 'c'
    i=21
  when 'd'
    i=31
  when 'e'
    i=41
  end
  print  %x{clear}
  show_cities(i)

  puts ""
  puts "Which city would you like more information about? Enter the number"

  input1 = -1
  while !(input1 >= i && input1 <= (i + 10)) do
  input1 = gets.strip.to_i
  end

city = BestCity::City.find(input1.to_i)

  show_city(city)

  puts ""
  puts "Would you like to continue? Enter Y or N"

  input = gets.strip.downcase
  if input == "y"
    start
  else
    puts ""
    puts "Thank you! Have a great day! Bye !"
    exit
  end
end