class TreePeople::CLI

Our CLI Controller

Attributes

available_options[RW]

Public Instance Methods

call() click to toggle source
# File lib/tree_people/cli.rb, line 6
def call
  Scraper.new.make_events
  @available_options = []
  puts "Welcome to TreePeople! We are excited to have you join our team of volunteers."
  menu
  exit
end
event_details() click to toggle source
# File lib/tree_people/cli.rb, line 85
def event_details
  space
  puts "Which event would you like to see details for?"
  space
  user_input = gets.chomp.to_i
  space
  if user_input <= @available_options.count
    event = @available_options[user_input - 1]
    puts "#{event.day}, #{event.month} #{event.date} from #{event.start_time} to #{event.end_time}"
    puts "#{event.name} in #{event.location}"
    puts "#{event.category}"
    space
    puts "#{event.description}"
    space
    if event.spots_open == ""
    elsif event.spots_open.start_with?("1 ")
      puts "There is 1 space available. Event capacity information is updated every hour."
      puts "To sign up, please visit TreePeople.org#{event.url}"
      space
    else
      puts "There are #{event.spots_open}"
      puts "To sign up, please visit TreePeople.org#{event.url}"
      space
    end
    @available_options.clear
    menu_or_exit
  else
    invalid_selection
    event_details
  end
end
exit() click to toggle source
# File lib/tree_people/cli.rb, line 144
def exit
  puts "Thank you for considering TreePeople. We hope to see you at an event soon!"
end
invalid_selection() click to toggle source
# File lib/tree_people/cli.rb, line 123
def invalid_selection
  puts "That is not a valid selection, please try again."
  space
end
list_selection_events() click to toggle source
# File lib/tree_people/cli.rb, line 76
def list_selection_events
  counter = 1
  @available_options.each do |event|
    puts "  #{counter}. #{event.day}, #{event.month} #{event.date} - #{event.name}"
    counter +=1
  end
end
menu() click to toggle source
menu_or_exit() click to toggle source
options(options_list) click to toggle source
# File lib/tree_people/cli.rb, line 43
def options(options_list)
  options_list.each do |option|
    puts "  #{option}"
  end
  space
end
select_option(attribute) click to toggle source
# File lib/tree_people/cli.rb, line 51
def select_option(attribute)
  puts "Which #{attribute} would you like to see upcoming events for?"
  space
  user_input = gets.chomp.downcase
  space
  if Event.all.any?{|event| user_input == event.location.downcase || user_input == event.category.downcase || user_input == event.day.downcase || user_input == event.time_of_day.downcase}
    puts "We have the following upcoming events:"
  else
    invalid_selection
    select_option("#{attribute}")
  end
  Event.all.each do |event|
    if user_input == event.location.downcase
      @available_options << event
    elsif user_input == event.category.downcase
      @available_options << event
    elsif user_input == event.day.downcase
      @available_options << event
    elsif user_input == event.time_of_day.downcase
      @available_options << event
    end
  end
end
space() click to toggle source
# File lib/tree_people/cli.rb, line 118
def space
  puts " "
end