Class: CLI
- Inherits:
-
Object
- Object
- CLI
- Defined in:
- lib/swole-news/CLI.rb
Instance Method Summary collapse
- #action ⇒ Object
- #call ⇒ Object
- #goodbye ⇒ Object
- #list_articles ⇒ Object
- #list_workouts ⇒ Object
- #make_articles ⇒ Object
- #repeat ⇒ Object
- #view_articles(input) ⇒ Object
- #view_workouts ⇒ Object
Instance Method Details
#action ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/swole-news/CLI.rb', line 102 def action input = nil while input != "exit" puts "Please enter a number from the list to view the article or enter 'exit' to exit".colorize(:green) input = gets.strip.downcase if input =~ /^-?[0-9]+$/ && input.to_i.between?(1, @articles.size) @article = @articles[input.to_i - 1] view_articles(input) view_workouts break elsif input == "exit" break else puts "Either the number you entered is out of range or is not recognized by the system.".colorize(:red) end end end |
#call ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/swole-news/CLI.rb', line 3 def call puts" || ||".colorize(:red) puts" |||||| ||||||".colorize(:red) puts"=========||||||||=======".colorize(:red)+"SWOLENEWS".colorize(:color => :black, :background => :light_blue).underline+"=======||||||||=========".colorize(:red) puts" |||||| ||||||".colorize(:red) puts" || ||".colorize(:red) puts "" puts "Tired of your old workout routine? Need some guidance or something new? Look no further!".colorize(:green) sleep(1.5) puts "SwoleNews has got your back!".colorize(:green) sleep(1.5) puts "" puts "Here is what's latest in workout.".colorize(:color => :blue).underline puts "" make_articles list_articles sleep(1) action sleep(1) goodbye end |
#goodbye ⇒ Object
120 121 122 |
# File 'lib/swole-news/CLI.rb', line 120 def goodbye puts "Keep up the good work and stay swole! See you soon!".colorize(:yellow) end |
#list_articles ⇒ Object
32 33 34 35 36 37 |
# File 'lib/swole-news/CLI.rb', line 32 def list_articles @articles.each.with_index(1) do |article, i| puts "#{i}.".colorize(:blue)+ " #{article.title}".colorize(:red) + " * #{article.read_time} *" puts "--------------------------------------------------------------------------------------------------------".colorize(:green) end end |
#list_workouts ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/swole-news/CLI.rb', line 54 def list_workouts sleep(1) puts "Now listing the workouts...".colorize(:blue) puts "---------------------------".colorize (:yellow) sleep(1.5) @article.workouts.each.with_index(1) do |workout, i| puts "#{i}. #{workout.title}".upcase.colorize(:blue) puts "**#{workout.definition}**".colorize(:yellow) end end |
#make_articles ⇒ Object
25 26 27 28 29 30 |
# File 'lib/swole-news/CLI.rb', line 25 def make_articles scraped_articles = Scraper.scrape_page Article.create_from_collection(scraped_articles) @articles = Article.all @articles end |
#repeat ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/swole-news/CLI.rb', line 87 def repeat input = nil while input != "exit" puts "Please type 'menu' to go back to the main menu or 'exit' to exit".colorize(:green) input = gets.strip.downcase if input == "menu" list_articles action break elsif input == "exit" break end end end |
#view_articles(input) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/swole-news/CLI.rb', line 39 def view_articles(input) puts "" sleep(1) puts "Viewing article no.#{input}".colorize(:blue) puts "" puts "== == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == ==" sleep(1.5) puts "#{@article.title}".colorize(:red) + " * #{@article.read_time} *" puts "#{@article.description}...".colorize(:yellow) puts "To read more go to:".colorize(:green) + " #{@article.url}".colorize(:blue) puts "== == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == ==" puts "" sleep(1) end |
#view_workouts ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/swole-news/CLI.rb', line 65 def view_workouts input = nil while input != "exit" puts "Would you like to view the workouts listed inside the article?".colorize(:green) puts "If yes, please type 'yes' or 'menu' to go back to the main menu or 'exit' to exit.".colorize(:green) input = gets.strip.downcase if input == "yes" list_workouts repeat break elsif input == "menu" list_articles action break elsif input == "exit" break else puts "Not sure what you typed.".colorize(:red) end end end |