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
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
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
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