Class: Snacks::CLI

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

Instance Method Summary collapse

Instance Method Details

#callObject



3
4
5
6
7
8
9
# File 'lib/snacks/cli.rb', line 3

def call 
  intro
  show_nuts_list
  show_data
  choose_another?
  # goodbye
end

#choose_another?Boolean

Returns:

  • (Boolean)


47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/snacks/cli.rb', line 47

def choose_another?
  while true
    print "\nWould you like to choose another nut variety to learn more about: (y/n) "
    input = gets.chomp.downcase.to_s
    if input == "y" 
        show_nuts_list
        show_data
    elsif input == "n"
        goodbye  
    else
        puts "\nPlease choose (y/n)."
    end 
  end 
end

#goodbyeObject



62
63
64
65
# File 'lib/snacks/cli.rb', line 62

def goodbye
  puts "\nThank you for visiting, see you next time!"
  exit!
end

#introObject



11
12
13
14
15
16
# File 'lib/snacks/cli.rb', line 11

def intro 
  puts "Hi, Welcome to Nuts!"
  # sleep 2
  puts "Here is a list of some of the most common nuts!"
  # sleep 2
end

#show_dataObject



39
40
41
42
43
44
45
# File 'lib/snacks/cli.rb', line 39

def show_data
  data = Snacks::NutsData.about_nut_info
  puts "\n========== #{data.type} =========="
  data.nut_facts.each do |fact|
    puts fact
  end
end

#show_nuts_listObject



18
19
20
21
22
23
24
# File 'lib/snacks/cli.rb', line 18

def show_nuts_list
  these = Snacks::NutsData.new #Snacks::NutData
  these.nuts.each.with_index(1) do |nut, index|
    puts "\n#{index}. #{nut.capitalize}"
  end
  # sleep 2
end

#user_chooses_nutObject



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/snacks/cli.rb', line 26

def user_chooses_nut
  while true
    print "\nChoose the list number of the nut that you're interested in: "
    input = gets.chomp.to_i - 1
    if !(0..7).include?(input)
      puts "Please enter a number between 1 and 8"
    else
      break
    end
  end
  input
end