Class: RockNRoll::CLI

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

Instance Method Summary collapse

Instance Method Details

#callObject



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

def call
  puts "~~~~~Welcome to the Rock 'n' Roll 2018-19 races!~~~~~"
  sleep(1)
  RockNRoll::Scraper.new.create_races
  show_list
  menu
end

#exit_programObject



47
48
49
# File 'lib/rock_n_roll/cli.rb', line 47

def exit_program
  puts "Thanks for checking, and keep on training!"
end


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rock_n_roll/cli.rb', line 18

def menu
  input = nil
    puts "Enter the number of the race you'd like more information about. Alternatively, type 'list' to see the full list of races, or type 'exit':"
    while input != "exit"
    input = gets.strip.downcase
    if input.to_i > 0 && input.to_i <= RockNRoll::Race.all.length
      race = RockNRoll::Race.retrieve(input.to_i)
      show_details(race)
      puts ""
      puts "Enter another number to see race details. Type 'list' to see the full list or 'exit':"
    elsif input == "list"
      show_list
    elsif input == "exit"
      exit_program
    else
      puts "Sorry, please enter a valid number or type 'list' or 'exit':"
    end
  end
end

#show_details(race) ⇒ Object



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

def show_details(race)
  puts "~*~*~*~*~*~*~* Details for #{race.location} ~*~*~*~*~*~*~*"
  puts "Date(s):              #{race.date}"
  puts "Distance(s):          #{race.distances}"
  puts "Description:          #{race.description}"
  puts "Event Hashtag:        #{race.hashtag}"
  puts "Event URL:            #{race.url}"
end

#show_listObject



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

def show_list
  @races = RockNRoll::Race.all
  @races.each.with_index(1) do |race, index|
    puts "#{index}. #{race.location}"
  end
end