Class: BirthYearAlbum::CLI

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

Overview

CLI controller

Instance Method Summary collapse

Instance Method Details

#callObject



5
6
7
# File 'lib/birth_year_album/cli.rb', line 5

def call
  menu
end

#find_album(year) ⇒ Object



46
47
48
# File 'lib/birth_year_album/cli.rb', line 46

def find_album(year)
  BirthYearAlbum::Album.album_by_year(year)
end

#get_yearObject



50
51
52
53
# File 'lib/birth_year_album/cli.rb', line 50

def get_year
  puts "Which year were you born? Type exit to quit the program."
  input = gets.strip.downcase
end


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/birth_year_album/cli.rb', line 9

def menu
  input = nil
  while input != "exit"
    input = get_year
    if input.to_i > 0 #checks to see if input is an integer or exit
      if input.to_i >= 1956 && input.to_i <= 2015 #checks qualifying years
        album = find_album(input.to_i)
        puts ""
        puts "The top album of #{album.year} was:"
        puts ""
        puts "----------------------------------------------"
        puts ""
        puts "#{album.name} by #{album.artist}"
        puts ""
        puts "----------------------------------------------"
        puts ""
      elsif input.to_i < 1956
        puts ""
        puts "There are no records of top selling albums before 1956. Try another year."
        puts ""
      else
        puts ""
        puts "This is not a valid year. Try again!"
        puts ""
      end
    elsif input == "exit"
      puts ""
      puts "Thanks! See you next time."
      puts ""
    else
      puts ""
      puts "I'm not sure what you are looking for try again."
      puts ""
    end
  end
end