Class: Markets::CLI
- Inherits:
-
Object
- Object
- Markets::CLI
- Defined in:
- lib/markets/cli.rb
Instance Method Summary collapse
Instance Method Details
#call ⇒ Object
5 6 7 8 |
# File 'lib/markets/cli.rb', line 5 def call list_stories end |
#end_program ⇒ Object
49 50 51 |
# File 'lib/markets/cli.rb', line 49 def end_program puts "Thank you for using the Markets gem, come back soon!" end |
#list_stories ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/markets/cli.rb', line 10 def list_stories puts "\e[H\e[2J" puts "Here's the latest finance news from The Atlantic: " puts "" @story_items = Markets::News.create_stories @story_items.each.with_index(1) do |story, i| puts "\t#{i}. #{story.title}\n" puts " " puts "\tPublished on #{story.date.first}\tWritten by #{story.author}\n" puts " " end end |
#menu ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/markets/cli.rb', line 23 def input = nil while input != "exit" puts "\nEnter the number of the news story you would like to read or type 'list' to see the article list again or 'exit' to exit:" input = gets.strip.downcase if input.to_i > 0 && @story_items[input.to_i-1] != nil the_story = @story_items[input.to_i-1] puts "\e[H\e[2J" puts "\t#{the_story.title}\n" puts "\n\tPublished on #{the_story.date.first}\tWritten by #{the_story.author}\n" puts "\n\tStory summary: " puts "\t#{the_story.content}" puts "\nRead more here by following this link:\nhttps://www.theatlantic.com#{the_story.link}" elsif input == "list" list_stories elsif input == "exit" puts "\e[H\e[2J" end_program else puts "Error, please enter the number of the story you wish to read!" end end end |