Class: WorldTraveler::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/world_traveler/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
# File 'lib/world_traveler/cli.rb', line 3

def call
  system("clear")
  WorldTraveler::Display.welcome_message
  sleep(2)

  @input = ""
   
  while @input != "exit"
    get_continents
    list_continents
    get_user_choice
    next_action
  end 
  goodbye
end

#get_continentsObject



19
20
21
# File 'lib/world_traveler/cli.rb', line 19

def get_continents
  @continent = WorldTraveler::Continents.all
end

#get_user_choiceObject



35
36
37
38
# File 'lib/world_traveler/cli.rb', line 35

def get_user_choice
  chosen_continent = gets.strip.to_i
  show_highlights_for(chosen_continent) 
end

#get_user_highlight(cont) ⇒ Object



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

def get_user_highlight(cont)
  puts "\nChoose a highlight in #{cont.name} to see more details.".light_blue.bold
  input = (gets.strip.to_i)
  if input.between?(1,cont.highlights.size)
    highlight = cont.highlights[input-1]
    # highlight.index = input.to_i-1
    highlight.get_highlight_details
    show_highlight_details(highlight)
  else
    puts "Not sure what you mean. You must enter a number between 1 - #{cont.highlights.size}."
    get_user_highlight(cont)
  end
end

#goodbyeObject



81
82
83
84
# File 'lib/world_traveler/cli.rb', line 81

def goodbye
  system("clear")
  WorldTraveler::Display.goodbye
end

#list_continentsObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/world_traveler/cli.rb', line 23

def list_continents
    # system("clear")
    WorldTraveler::Display.continent_list
  
  @continent.each.with_index(1) do |continent, index| 
    puts "#{index}. #{continent.name}".center(150).rjust(10)
    puts "-----------------------------------------".green.center(165)
  end
  puts ""
  puts "Where would you like to go? (Choose 1-#{@continent.size})".center(152).green.bold
end

#next_actionObject



75
76
77
78
79
# File 'lib/world_traveler/cli.rb', line 75

def next_action
  puts "\nType 'exit' to exit or any key to return to main menu.".green.bold
  @input = gets.strip
  system("clear")
end

#show_highlight_details(highlight) ⇒ Object



69
70
71
72
73
# File 'lib/world_traveler/cli.rb', line 69

def show_highlight_details(highlight)
  puts "#{highlight.name}".center(170,"-").bold
  highlight.info.each {|i| puts "\n#{i}\n"}
  puts "-".center(170, "-").bold
end

#show_highlights_for(chosen_continent) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/world_traveler/cli.rb', line 40

def show_highlights_for(chosen_continent)
    system("clear")
    if chosen_continent.between?(1,@continent.size)
        cont = @continent[chosen_continent - 1]
        cont.get_highlights
        puts "Here are highlights in #{cont.name}".light_blue.bold
        cont.highlights.each.with_index(1) do |high, idx|
            puts "#{idx}. #{high.name}"
        end
        get_user_highlight(cont)
    else
        puts "Not sure what you mean. You must enter a number between 1 - #{@continent.size}."
    end
end