Class: TutorialCentral::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/tutorial_central/cli.rb

Instance Method Summary collapse

Instance Method Details

#basic_menuObject



7
8
9
10
11
12
13
14
15
# File 'lib/tutorial_central/cli.rb', line 7

def basic_menu
  choose do |menu|
    say 'Would you like to see categories or the latest tutorials?' 
    menu.prompt = "You can also type 'exit' to exit."
    menu.choice(:categories) {category_menu}
    menu.choice(:latest)  {display_tutorials}
    menu.hidden(:exit) {exit}
  end
end

#callObject



2
3
4
5
# File 'lib/tutorial_central/cli.rb', line 2

def call
  puts "Welcome to Tutorial Central!"
  basic_menu
end

#category_menuObject



17
18
19
20
21
22
23
24
25
# File 'lib/tutorial_central/cli.rb', line 17

def category_menu
  categories = TutorialCentral::Scraper.scrape_categories("http://hackr.io")
  options = categories.keys.to_a
  say "Here are the categories."
  choose do |menu|
    menu.prompt = 'Choose one.'
    menu.choices(*options) {|answer| display_tutorials(categories[answer],answer) }
  end  
end

#display_tutorials(url = "http://hackr.io/latest", category = "Latest") ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/tutorial_central/cli.rb', line 27

def display_tutorials(url="http://hackr.io/latest", category="Latest")
  tutorials = TutorialCentral::Scraper.scrape_tutorials(url)
  options = tutorials.keys.to_a
  say "Here are the tutorials."
  choose do |menu|
    menu.prompt = 'Choose one.'
    menu.choices(*options) {|answer| say "#{answer} is located at #{tutorials[answer]}." }
  end
  if agree("Return to main menu?", true)
    basic_menu
  else
    say "Thank you for using Tutorial Central!"
    exit
  end
end