Class: CheeseBoard::CLI

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

Instance Method Summary collapse

Instance Method Details

#box_a_string(string) ⇒ Object



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

def box_a_string(string)
  puts ""
  print " "
  (string.length+2).times do print "_" end
  puts ""
  puts ""
  puts "| #{string} |"
  print " "
  (string.length+2).times do print "_" end
  puts ""
end

#callObject



2
3
4
5
6
7
# File 'lib/cheese_board/cli.rb', line 2

def call
  greeting = "Welcome to Cheese Board"
  box_a_string(greeting)
  puts "Are you ready to explore the CHEEZZZYY-WORLD?".colorize(:yellow)
  run
end

#get_cheese_typesObject



20
21
22
# File 'lib/cheese_board/cli.rb', line 20

def get_cheese_types
  CheeseBoard::CheeseType.all.sort_by {|c| c.name}
end

#get_user_cheeseObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/cheese_board/cli.rb', line 76

def get_user_cheese
  puts ""
  input = gets.strip
  puts ""
  sleep 1

  if input == "exit"
    say_good_bye
  elsif input == "back"
    run
  elsif valid_input?(input, @cheese_type.cheeses)
    show_cheese_for(input.to_i)
  else
    puts "I dont understand, please try again"
    get_user_cheese_type
  end
end

#get_user_cheese_typeObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cheese_board/cli.rb', line 34

def get_user_cheese_type
  puts ""
  input = gets.strip
  puts ""
  sleep 1

  if input =="exit"
    say_good_bye
  elsif valid_input?(input, @cheese_types)
    show_cheese_type_for(input.to_i)
  else
    puts "I dont understand, please try again"
    get_user_cheese_type
  end
end

#list_cheese_typesObject



14
15
16
17
18
# File 'lib/cheese_board/cli.rb', line 14

def list_cheese_types
  @cheese_types = get_cheese_types
  puts "\nWhat type of cheese are you interested in. Please enter number of the cheese, or #{ColorizedString["exit"].colorize(:red)}"
  print_list(@cheese_types)
end


24
25
26
27
28
# File 'lib/cheese_board/cli.rb', line 24

def print_list(array)
  array.each.with_index(1) do |value, index|
    puts "#{index}. #{value.name}"
  end
end

#runObject



9
10
11
12
# File 'lib/cheese_board/cli.rb', line 9

def run
  list_cheese_types
  get_user_cheese_type
end

#say_good_byeObject



105
106
107
108
109
# File 'lib/cheese_board/cli.rb', line 105

def say_good_bye
  puts "BON APPETIT!".colorize(:yellow)
  puts "SEE YOU NEXT TIME!".colorize(:yellow)
  exit
end

#show_cheese_for(chosen_cheese) ⇒ Object



94
95
96
97
98
99
100
101
102
103
# File 'lib/cheese_board/cli.rb', line 94

def show_cheese_for(chosen_cheese)
   cheese = @cheese_type.cheeses[chosen_cheese-1]
   puts "CHARACTERISTICS".colorize(:blue)
   puts "#{cheese.cheese_description}"
   puts ""
   puts "BEST MATE".colorize(:blue)
   puts "#{cheese.pair_wine}"
   puts "\nEnter #{ColorizedString["back"].colorize(:red)} to discover more cheeses, or #{ColorizedString["exit"].colorize(:red)}"
   get_user_cheese
end

#show_cheese_type_for(chosen_cheese_type) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/cheese_board/cli.rb', line 63

def show_cheese_type_for(chosen_cheese_type)
  @cheese_type = @cheese_types[chosen_cheese_type-1]
  @cheese_type.get_cheeses
  puts "Here are the information for #{@cheese_type.name}"
  cheese_type_char = @cheese_type.char
  box_a_string(cheese_type_char)

  puts "\nEnter a number for the cheese you are interested in, #{ColorizedString["back"].colorize(:red)} to discover more, or #{ColorizedString["exit"].colorize(:red)}"
  print_list(@cheese_type.cheeses)

  get_user_cheese
end

#valid_input?(input, array) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/cheese_board/cli.rb', line 30

def valid_input?(input,array)
  input.to_i > 0 && input.to_i <= array.length
end