class WhatAWorld::CLI

Public Instance Methods

again?() click to toggle source
# File lib/what_a_world/cli.rb, line 131
def again?
    repeat = true
        puts ""
    while repeat
        puts "Would you like to search for other data?".colorize(:red)
        puts "Type 'yes' or 'no'"
        print ":"
        input = gets.strip.to_s.upcase 
        if input != "YES" && input != "NO" && input != "Y" && input != "N"
            repeat = true
        else
            repeat = false
        end
    end
    input == "YES" || input == "Y" ? true : false
end
call() click to toggle source
# File lib/what_a_world/cli.rb, line 2
def call
    welcome
    again = true
    while again
        letter = select_letter
        if letter != "X"
            scraper = WhatAWorld::Scraper::ScraperCli.new(letter)
            scraper.find_all_countries
            scraper.find_countries_by_letter
            letter_countries = scraper.letter_countries
            letter_url_extensions = scraper.letter_url_extensions

            country_hash = get_country(letter_countries, letter_url_extensions)
            country = WhatAWorld::Country.new(country_hash)
            country.scrape 
    
            country.get_issues
            
            print_results(country)
        else
            puts "No locations start with 'X'!".colorize(:red)
        end
        again = again?
    end
    goodbye
 end
get_country(letter_countries, letter_url_extensions) click to toggle source
# File lib/what_a_world/cli.rb, line 61
def get_country(letter_countries, letter_url_extensions)
    country_hash = {}
    index = 0
    letter_countries.each{|country|
        index += 1
        puts "#{index}. #{country}"
    }

    number = ""
    puts ""
    loop do
        puts "Choose a country by number".colorize(:red)
        print ":"
        number = gets.strip
        break if (number.to_i.between?(1, index) && whole?(number))
    end 

    puts ""
   country_hash[letter_countries[number.to_i - 1]] = letter_url_extensions[number.to_i - 1]  
   country_hash  
end
goodbye() click to toggle source
# File lib/what_a_world/cli.rb, line 37
def goodbye
    puts ""
    "Goodbye, and peace to the world!".print_fit
    puts ""
end
print_results(country) click to toggle source
select_letter() click to toggle source
# File lib/what_a_world/cli.rb, line 43
def select_letter
    letter = nil
    puts ""
    while !(/\A[A-Z]\z/.match(letter))
        sleep(0.5)
        puts "Select a location by typing its first letter, A to Z".colorize(:red)
        print ":"
        letter = gets.strip.upcase 
    end 
    puts ""
    letter
end
welcome() click to toggle source
# File lib/what_a_world/cli.rb, line 29
def welcome 
    "What A World!".print_fit
    sleep(1.0)
    "Explore transnational issues on a location-by-location basis.".print_fit
    sleep(1.0)
    "Information provided by the C.I.A.".print_fit
end
whole?(number) click to toggle source
# File lib/what_a_world/cli.rb, line 56
def whole?(number)
    regex = /\A[1-9][0-9]*\z/ 
    regex.match(number)
end