class Cli

Attributes

content[RW]

Public Class Methods

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
main_menu() click to toggle source

Brings up .greeting, begins the search process, and then displays the provided results

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
search_menu_command() click to toggle source

Runs the specific search requested by the user and returns results as an array of Content objects, asks the user to submit a valid command, or exits the program

# File lib/services/cli.rb, line 37
def self.search_menu_command
    command = self.get_input()

    case command
    when "s"
      self.keyword_search()
      Content.all
    when "i"
      self.image_search()
      Content.all
    when "a"
      self.audio_search()
      Content.all
    when "v"
      self.video_search()
      Content.all
    when "exit"
      puts "\n\nThank you, please come again!"
      exit
    else
      puts "\n\nCommand not recognized, please try again."
      self.main_menu
    end
end