Class: CountriesOfTheWorld::CLI

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

Instance Method Summary collapse

Instance Method Details

#callObject



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

def call
  display_header
  scraper = CountriesOfTheWorld::Scraper.new
  scraper.scrape_page
  input = keep_going
  
  while input.downcase != "exit"
    if input.to_i > 0 && input.to_i <= CountriesOfTheWorld::Country.all.size
    #if input is a number 
      display_detail(scraper, input.to_i-1)

      puts "Would you like to view another country? Y/N"
      input = gets.strip.downcase
      if input == "n"
        puts "All right, see you next time!".bold.green
        exit
      else
        input = keep_going
      end
    elsif input.downcase == "list"
      list_all_country
      input = keep_going
    else 
      puts "Please enter a valid response".bold.red
      input = keep_going
    end
  end
  puts "OKIE DOKIE! SEE YOU NEXT TIME!!! GO RUBY!!!".bold.green
end

#display_detail(scraper, input) ⇒ Object



54
55
56
57
58
# File 'lib/countries_of_the_world/cli.rb', line 54

def display_detail(scraper, input)
  info = scraper.country_page(CountriesOfTheWorld::Country.all[input].url)
  CountriesOfTheWorld::Country.all[input].add_info(info)
  CountriesOfTheWorld::Country.all[input].list_detail
end

#display_headerObject



33
34
35
36
37
# File 'lib/countries_of_the_world/cli.rb', line 33

def display_header
  puts "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++".bold.on_cyan.blink
  puts "++++++++++++*****".bold.on_cyan.blink+"Welcome to the country data from World Bank".upcase.bold+"*****++++++++++++".bold.on_cyan.blink
  puts "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++".bold.on_cyan.blink
end

#keep_goingObject



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

def keep_going
  puts "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++".green
  puts "+".green+"Due to the size of data, please maximize your screen for optimal experiences".red.on_yellow+"+".green
  puts "+".green+"Enter exit to exit the program                                              "+"+".green
  puts "+".green+"Enter list to list all countries                                            "+"+".green
  puts "+".green+"Enter a number to see a country's detail                                    "+"+".green
  puts "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++".green
  
  gets.strip
end

#list_all_countryObject



50
51
52
# File 'lib/countries_of_the_world/cli.rb', line 50

def list_all_country
CountriesOfTheWorld::Country.list_countries(4) #display 4 in a row
end