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
53 54 55 56 57 58 59 |
# File 'lib/top25/cli.rb', line 53 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. e for exit\n5. b for going back" take_input end |
#make_places(name) ⇒ Object
47 48 49 50 51 |
# File 'lib/top25/cli.rb', line 47 def make_places(name) scraper = Top25::Scraper.new arrofplaces = scraper.scrap_index_page(name) Top25::Place.create_from_collection(arrofplaces) end |
#run(place) ⇒ Object
41 42 43 44 45 |
# File 'lib/top25/cli.rb', line 41 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 38 39 |
# File 'lib/top25/cli.rb', line 15 def search(s) if s == "1" puts "Top 25 Hotels" puts "=================".colorize(:blue) run("Hotels") take_input elsif s == "2" puts "Top 25 Restaurants" puts "=================".colorize(:blue) run("Restaurants") take_input elsif s == "3" puts "Top 25 Beaches" puts "=================".colorize(:blue) run("Beaches") take_input elsif s == "b" home elsif !(s.to_i.between?(1, 3)) && (s != "e") puts "sorry, you only can search hotels,restaurants and beaches" take_input elsif s == "e" 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 |