Class: NowPlaying::CLI

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

Instance Method Summary collapse

Instance Method Details

#callObject



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

def call
  start
end

#listObject



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

def list
  puts ""
  puts "************* Now Playing in Theatres *************"
  puts ""
  NowPlaying::Movie.all.each.with_index(1) do |movie, i|
    puts "#{i}. #{movie.name}"
  end
  puts ""
end


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

def print_movie(movie)
  puts ""
  puts "-------------- #{movie.name} --------------"

  puts ""
  puts movie.summary
  puts ""

  puts "Starring: #{movie.stars}"
  puts ""
end

#startObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/now_playing/cli.rb', line 28

def start
  list
  input = nil
  while input != "exit"
    puts ""
    puts "What movie would you more information on, by name or number?"
    puts ""
    puts "Enter list to see the movies again."
    puts "Enter exit to end the program."
    puts ""
    input = gets.strip
    if input == "list"
      list
    elsif input.to_i == 0
      if movie = NowPlaying::Movie.find_by_name(input)
        print_movie(movie)
      end
    elsif input.to_i > 0
      if movie = NowPlaying::Movie.find(input.to_i)
        print_movie(movie)
      end
    end
  end
  puts "Goodbye!!!"
end