Class: TopApps::CLI
- Inherits:
-
Object
- Object
- TopApps::CLI
- Defined in:
- lib/top_apps/cli.rb
Class Method Summary collapse
- .add_attributes(app) ⇒ Object
- .back_to_apps ⇒ Object
- .create_apps ⇒ Object
- .display_apps ⇒ Object
- .display_profile(rank) ⇒ Object
- .greeting ⇒ Object
- .quit ⇒ Object
- .run ⇒ Object
- .select_app ⇒ Object
- .sorry ⇒ Object
Class Method Details
.add_attributes(app) ⇒ Object
13 14 15 16 |
# File 'lib/top_apps/cli.rb', line 13 def self.add_attributes(app) profile_hash = TopApps::Scraper.scrape_profile(app.profile_url) app.add_attributes_from_profile(profile_hash) end |
.back_to_apps ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/top_apps/cli.rb', line 75 def self.back_to_apps puts "\n" puts "If you want to go back to the apps, enter 'back', if you want to quit, enter 'quit'." input = gets.strip.downcase case input when "back" display_apps when "quit" quit else sorry back_to_apps end end |
.create_apps ⇒ Object
8 9 10 11 |
# File 'lib/top_apps/cli.rb', line 8 def self.create_apps index_array = TopApps::Scraper.scrape_index("https://www.apple.com/itunes/charts/") TopApps::App.create_apps_from_index(index_array) end |
.display_apps ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/top_apps/cli.rb', line 24 def self.display_apps puts "\n" puts "Here are the top #{TopApps::App.all.size} free apps in the Apple Store right now:" TopApps::App.all.each do |app| puts "#{app.rank}. #{app.name} - #{app.category}" end select_app end |
.display_profile(rank) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/top_apps/cli.rb', line 62 def self.display_profile(rank) app = TopApps::App.find_by_rank(rank) puts "\n" puts "#{app.name}" puts "Ranked ##{app.rank}" puts "Category: #{app.category}" puts "Developer: #{app.developer}" puts "Rating: #{app.}" puts "Editor's Notes:" puts "#{app.notes}" back_to_apps end |
.greeting ⇒ Object
18 19 20 21 22 |
# File 'lib/top_apps/cli.rb', line 18 def self.greeting puts "Welcome to Top Apps!" puts "Top Apps is a CLI that displays the hottest apps in the Apple Store right now." puts "You can select an app to learn more about it." end |
.quit ⇒ Object
51 52 53 54 55 |
# File 'lib/top_apps/cli.rb', line 51 def self.quit puts "\n" puts "Thanks for using Top Apps. Goodbye!" exit end |
.run ⇒ Object
2 3 4 5 6 |
# File 'lib/top_apps/cli.rb', line 2 def self.run create_apps greeting display_apps end |
.select_app ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/top_apps/cli.rb', line 33 def self.select_app puts "\n" puts "To learn more about an app, enter its rank." puts "To quit, enter 'quit'." input = gets.strip.downcase if input.to_i.between?(1, TopApps::App.all.size) app = TopApps::App.find_by_rank(input) add_attributes(app) if !app.developer display_profile(input) elsif input == "quit" quit else sorry select_app end end |
.sorry ⇒ Object
57 58 59 60 |
# File 'lib/top_apps/cli.rb', line 57 def self.sorry puts "\n" puts "I'm sorry, I don't understand you." end |