Class: CombineHashtags::Router

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

Overview

Router for CLI

Instance Method Summary collapse

Constructor Details

#initialize(controller) ⇒ Router

Returns a new instance of Router.



5
6
7
8
# File 'lib/combine_hashtags/cli/router.rb', line 5

def initialize(controller)
  @controller = controller
  @running    = true
end

Instance Method Details

#display_tasksObject



38
39
40
41
42
43
44
45
46
# File 'lib/combine_hashtags/cli/router.rb', line 38

def display_tasks
  puts ""
  puts "What do you want to do next?"
  puts "1 - Fetch data for a new profile"
  puts "2 - See profile's most popular hashtags"
  puts "3 - Start a search"
  puts "   ---"
  puts "0 - Stop and exit the program"
end

#route_action(action) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/combine_hashtags/cli/router.rb', line 22

def route_action(action) 
  case action
  when 1 then @controller.setup 
  when 2 then @controller.list 
  when 3 then @controller.search
  
  when 0 then stop
  else
    puts "Please select an option"
  end
end

#runObject



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/combine_hashtags/cli/router.rb', line 10

def run
  puts "Welcome!"
  puts "---"

  while @running
    display_tasks
    action = gets.chomp.to_i
    print `clear`
    route_action(action)
  end
end

#stopObject



34
35
36
# File 'lib/combine_hashtags/cli/router.rb', line 34

def stop
  @running = false
end