class Cli
Attributes
content[RW]
Public Class Methods
audio_search()
click to toggle source
Gets search terms and creates Content
objects based on the provided results
# File lib/services/cli.rb, line 109 def self.audio_search Content.all.clear puts "\n\nPlease enter your audio search terms.\n\n" terms = gets.chomp! terms = terms.split(" ").join("%20") search_results = CliNasaAPI.media_search("audio", terms) search_results = search_results["collection"]["items"] search_results.each do |result| attributes = result["data"][0] links = result["links"][0] if result["links"] != nil title = attributes["title"] description = attributes["description"] keywords = attributes["keywords"] link = links["href"] if links != nil Content.add_content(title, description, keywords, link) end end
display_content(results)
click to toggle source
Method for displaying a piece of content, navigating thorugh its data, and prompting the user for their next valid command
# File lib/services/cli.rb, line 156 def self.display_content(results) input = "" page = 1 while input != "s" current = results[page-1] puts "\n\nPage #{page}: #{current.title}" if current.link == nil puts "Link: link not available" else puts "Link: #{current.link}" end puts "\n\nHere are your available commands:" puts ">> k - Displays the content's keywords" puts ">> d - Displays the content's description." puts ">> n - Shows the next result" puts ">> p - Shows the previous result" puts ">> s - Start a new search." input = self.get_input() case input when "k" puts "\n\nKeywords : #{current.keywords}\n" when "d" puts "\n\nDescription : #{current.description}\n" when "n" if page < results.length page += 1 else puts "\n\nThere are no further results.\n" end when "p" if page > 1 page -= 1 else puts "\n\nYou're at the top of your results.\n" end when "s" self.main_menu else puts "\n\nCommand not recognized, please try again.\n" end end end
get_input()
click to toggle source
Prompts the user for input
# File lib/services/cli.rb, line 28 def self.get_input puts "\n\nPlease make a selection.\n\n" input = gets.chomp! input end
greeting()
click to toggle source
Welcomes users and provides the list of available commands
# File lib/services/cli.rb, line 18 def self.greeting puts "\n\nWelcome to the NASA-CLI, here are your available commands: " puts ">> s - a keyword search of the Nasa Image and Video Library" puts ">> i - a search of the library focused for only images" puts ">> a - a search of the library focused for only audio clips" puts ">> v - a search of the library focused for only videos" puts ">> exit - exit NASA-CLI\n" end
image_search()
click to toggle source
Gets search terms and creates Content
objects based on the provided results
# File lib/services/cli.rb, line 86 def self.image_search Content.all.clear puts "\n\nPlease enter your image search terms.\n\n" terms = gets.chomp! terms = terms.split(" ").join("%20") search_results = CliNasaAPI.media_search("image", terms) search_results = search_results["collection"]["items"] search_results.each do |result| attributes = result["data"][0] links = result["links"][0] title = attributes["title"] description = attributes["description"] keywords = attributes["keywords"] link = links["href"] Content.add_content(title, description, keywords, link) end end
keyword_search()
click to toggle source
Gets search terms and creates Content
objects based on the provided results
# File lib/services/cli.rb, line 63 def self.keyword_search Content.all.clear puts "\n\nPlease enter your search terms.\n\n" terms = gets.chomp! terms = terms.split(" ").join("%20") search_results = CliNasaAPI.basic_search(terms) search_results = search_results["collection"]["items"] search_results.each do |result| attributes = result["data"][0] links = result["links"][0] if result["links"] != nil title = attributes["title"] description = attributes["description"] keywords = attributes["keywords"] link = links["href"] if links != nil Content.add_content(title, description, keywords, link) end end
run()
click to toggle source
Method called at startup that brings up main menu
# File lib/services/cli.rb, line 6 def self.run self.main_menu end
video_search()
click to toggle source
Gets search terms and creates Content
objects based on the provided results
# File lib/services/cli.rb, line 132 def self.video_search Content.all.clear puts "\n\nPlease enter your video search terms.\n\n" terms = gets.chomp! terms = terms.split(" ").join("%20") search_results = CliNasaAPI.media_search("video", terms) search_results = search_results["collection"]["items"] search_results.each do |result| attributes = result["data"][0] links = result["links"][0] if result["links"] != nil title = attributes["title"] description = attributes["description"] keywords = attributes["keywords"] link = links["href"] if links != nil Content.add_content(title, description, keywords, link) end end