Class: HallidayWineList::CLI

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

Instance Method Summary collapse

Instance Method Details

#choose_categoryObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/halliday_wine_list/cli.rb', line 12

def choose_category
  categories = HallidayWineList::Category.all_categories
  if categories.count == 0
    site_error
  else
    puts ""
    puts "Categories:"
    list_categories
    puts ""
    puts "Select a category (1-#{categories.count}) to view the wines from that category, type 'list' to see all wines or type exit to leave."
    @input = gets.strip.downcase
    if users_choice >= 0 && users_choice < (categories.count)
      puts ""
      puts "Current selection: #{categories[users_choice].name}."
      puts "--------------------------------------------"
      print_category_wines
    elsif @input == "exit"
      goodbye
    elsif @input == "list"
      puts ""
      puts "Current selection: all red and white wines from the 2017 selection."
      puts "--------------------------------------------"
      print_all_wines
    else
      puts ""
      puts "Sorry, that input is not valid. Here are your options again."
      choose_category
    end
    next_steps
  end
end

#collect_dataObject



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

def collect_data
  HallidayWineList::Category.create_categories
end

#goodbyeObject



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

def goodbye
  puts "We hope you found a wine to your liking! Enjoy often, enjoy responsibly."
  exit
end

#list_categoriesObject



85
86
87
# File 'lib/halliday_wine_list/cli.rb', line 85

def list_categories
  HallidayWineList::Category.print_categories
end

#next_stepsObject



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

def next_steps
  puts ""
  puts "--------------------------------------------"
  puts "What would you like to do next? (1-2)"
  puts "1 View main menu"
  puts "2 Exit"
  input = gets.strip.to_i
  if input == 1
    choose_category
  elsif input == 2
    goodbye
  else
    puts ""
    puts "Sorry, that input is not valid. Please enter a valid input (1-2)."
    next_steps
  end
end


89
90
91
# File 'lib/halliday_wine_list/cli.rb', line 89

def print_all_wines
  HallidayWineList::Wine.print_wines
end


68
69
70
# File 'lib/halliday_wine_list/cli.rb', line 68

def print_category_wines
  HallidayWineList::Category.all_categories[users_choice].print_wines
end

#site_errorObject



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

def site_error
  puts ""
  puts "We're sorry. There seems to be an issue with the James Halliday Top Wines 2017 website at this time. Please check back again later."
  exit
end

#startObject



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

def start
  puts ""
  puts "James Halliday's Top Wines for 2017"
  puts "--------------------------------------------"
  puts "Retrieving all red and white varieties from the 2017 selection.."
  collect_data
  choose_category
end

#users_choiceObject



72
73
74
# File 'lib/halliday_wine_list/cli.rb', line 72

def users_choice
  @input.to_i - 1
end