class CommandLineInterface

require_relative “../best_boutique_hotels.rb”

Constants

BASE_URL

Public Instance Methods

add_details_to_hotels() click to toggle source
# File lib/best_boutique_hotels/command_line.rb, line 33
def add_details_to_hotels
  puts "Getting Hotel details...".white.on_blue.underline
  progressbar = ProgressBar.create(:total=>Hotel.all.size)
  Hotel.all.each_with_index do |hotel, index|
    progressbar.increment
    attributes = Scraper.scrape_hotel_page(hotel.hotel_url)
    hotel.add_hotel_attributes(attributes)
  end
end
begin_navigation() click to toggle source
# File lib/best_boutique_hotels/command_line.rb, line 43
def begin_navigation
  puts "www.boutiquehotelawards.com".white.on_blue.underline
  puts "A list of the top boutique hotels in the world in the following categories:".white.on_blue.underline
  puts ""
  Category.all.each_with_index do |c, i|
    puts "#{i+1}. #{c.name}".colorize(:blue)
  end
  category_navigation
end
category_navigation() click to toggle source
# File lib/best_boutique_hotels/command_line.rb, line 53
def category_navigation
  puts ""
  puts "Choose a category to view hotels.".white.on_blue.underline
  c_index = gets.strip
  if c_index.to_i.between?(1, Category.all.size)
    @current_category_index = c_index.to_i-1
    list_hotels(c_index.to_i-1)
  else
    puts "Yikes, try a valid category.".colorize(:red)
    category_navigation
  end
end
continue?() click to toggle source
# File lib/best_boutique_hotels/command_line.rb, line 104
def continue?
  puts ""
  puts "Would you like to continue? (Y/N)".white.on_blue
  answer = gets.strip.upcase
  if answer == "Y"
    repeat_navigation
  elsif
    answer == "N"
    puts "Bye!"
    exit
  else
    "I didn't understand you."
    continue?
  end
end
hotel_navigation() click to toggle source
# File lib/best_boutique_hotels/command_line.rb, line 76
def hotel_navigation
  puts ""
  puts "Choose a hotel to view details.".white.on_blue
  h_index = gets.strip
  if h_index.to_i.between?(1, @current_category.hotels.size)
    view_hotel(@current_category.hotels[h_index.to_i-1])
  else
    puts "Oops, that's not a valid hotel.".colorize(:red)
    hotel_navigation
  end
end
list_hotels(c_index) click to toggle source
# File lib/best_boutique_hotels/command_line.rb, line 66
def list_hotels(c_index)
  @current_category = Category.all[c_index]
  puts "#{@current_category.name} hotels:".white.on_blue.underline
  puts ""
  @current_category.hotels.each_with_index do |h, i|
    puts "#{i+1}. #{h.hotel_name}".colorize(:blue)
  end
  hotel_navigation
end
make_categories() click to toggle source
# File lib/best_boutique_hotels/command_line.rb, line 16
def make_categories
  categories_array = Scraper.scrape_index_page(BASE_URL)
  Category.create_from_collection(categories_array)
  puts "Getting Categories...".white.on_blue.underline
end
make_hotels() click to toggle source
# File lib/best_boutique_hotels/command_line.rb, line 22
def make_hotels
  hotels_array = []
  Category.all.each do |category|
    hotels_array = Scraper.scrape_category_page(category.url)
    category_hotels = Hotel.create_from_collection(hotels_array)
    category.add_hotels(category_hotels)
    puts "#{category.name} created.".colorize(:blue)
  end
end
repeat_navigation() click to toggle source
# File lib/best_boutique_hotels/command_line.rb, line 120
def repeat_navigation
  puts wrap("Would you like to go (back) to the hotel listings for #{@current_category.name} or go to the (categories) page?")
  answer = gets.strip.downcase
    if answer == "back"
      list_hotels(@current_category_index)
    elsif
      answer == "categories"
      @current_category = ""
      @current_category_index = 0
      begin_navigation
    else
      repeat_navigation
    end
  end
run() click to toggle source
# File lib/best_boutique_hotels/command_line.rb, line 9
def run
  make_categories
  make_hotels
  add_details_to_hotels
  begin_navigation
end
view_hotel(hotel) click to toggle source
# File lib/best_boutique_hotels/command_line.rb, line 88
def view_hotel(hotel)
  puts ""
  puts "#{hotel.hotel_name.upcase}".white.on_blue.underline
  puts wrap("#{hotel.headline}".colorize(:light_blue))
  puts " .     -     -     -     . "
  puts wrap("  Location: ".colorize(:blue) + "#{hotel.location}")
  puts wrap("  Category: ".colorize(:blue) + "#{hotel.category.name}")
  puts wrap("  Website: ".colorize(:blue) + "#{hotel.hotel_website}")
  puts wrap("  Number of Rooms: ".colorize(:blue) + "#{hotel.number_of_rooms}")
  puts wrap("  Price: ".colorize(:blue) + "#{hotel.price}")
  hotel.notes.each_with_index do |note, i|
    i == 0 ? (puts "  Additional Details:\n".colorize(:blue)  + wrap("    #{note}")) : (puts wrap("    #{note}"))
  end
  continue?
end