Class: Top25::Cli
- Inherits:
-
Object
- Object
- Top25::Cli
- Defined in:
- lib/top25/cli.rb
Instance Method Summary collapse
- #display_places ⇒ Object
- #home ⇒ Object
- #make_places(name) ⇒ Object
- #run(place) ⇒ Object
- #search(s) ⇒ Object
- #take_input ⇒ Object
Instance Method Details
#display_places ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/top25/cli.rb', line 51 def display_places Top25::Place.all.each do |pl| puts "#{pl.num}. #{pl.name}-based in: #{pl.location}" puts "Website: #{pl.url}" puts "-------------------------------------".colorize(:green) end end |
#home ⇒ Object
3 4 5 6 7 |
# File 'lib/top25/cli.rb', line 3 def home puts "Search for the best in the world, choose one of the follwing numbers" puts "1. Hotels\n2. Restaurants\n3. Beaches\n4. for exit" take_input end |
#make_places(name) ⇒ Object
45 46 47 48 49 |
# File 'lib/top25/cli.rb', line 45 def make_places(name) scraper = Top25::Scraper.new arrofplaces = scraper.scrap_index_page(name) Top25::Place.create_from_collection(arrofplaces) end |
#run(place) ⇒ Object
39 40 41 42 43 |
# File 'lib/top25/cli.rb', line 39 def run(place) make_places(place) #add_attributes display_places end |
#search(s) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/top25/cli.rb', line 15 def search(s) if s == "1" puts "Top 25 Hotels" puts "=================".colorize(:blue) run("Hotels") home elsif s == "2" puts "Top 25 Restaurants" puts "=================".colorize(:blue) run("Restaurants") home elsif s == "3" puts "Top 25 Beaches" puts "=================".colorize(:blue) run("Beaches") home elsif !(s.to_i.between?(1, 4)) puts "sorry, you only can search hotels,restaurants and beaches" home elsif s == "4" puts "Good bye ^ _ ^" end end |
#take_input ⇒ Object
9 10 11 12 13 |
# File 'lib/top25/cli.rb', line 9 def take_input input ="" input = gets.strip search(input) end |