Class: DutchTop40::CLI

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

Instance Method Summary collapse

Instance Method Details

#callObject



3
4
5
6
7
8
9
# File 'lib/dutch_top40/cli.rb', line 3

def call
    
    puts "Dutch Top40 - week  #{Time.now.strftime("%U")}", ""
    puts "One moment, acquiring data."
    list_songs
    menu
end

#goodbyeObject



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

def goodbye
    
    puts "See you next time..."
end

#list_songsObject



11
12
13
14
15
# File 'lib/dutch_top40/cli.rb', line 11

def list_songs
    @songs = DutchTop40::Songs.list
    print_songs
    puts
end

#logoObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/dutch_top40/cli.rb', line 50

def 
    puts "                                                                                                    
    `````````````````````   ````````````````````    ````````````````````             
   `:``````````````````.+. -.``````````````````-/` :```````````````````+.            
   :` `---:::::::---`  /Ny`:   `.-/+::+/:`     hm/:`.///////-///:-`   -Nd`           
  -.  ```oyyyyyyo```  .NN-/  ./oyyyo`+yyys/   +Mh.-`syyyyyy/.yyyyys. `dM:            
 `:     -yyyyyys`     hM+:`.+yyyyys.:yyyyyy- -Nm.: +yyyyyys`oyyyyyy/ sMs             
 :     `syyyyyy-     oMy.--syyyyyy:.yyyyyyy:`mM::`-yyyyyyy./yyyyyys./Md`             
:`     oyyyyyy+     :Mm./-yyyyyyy+`syyyyyys`yMo-.`syyyyyy/-yyyyyyo..NN.              
   .-     /yyyyyys`    `mM-:`syyyyyys`+yyyyyys./Md`: oyyyyyys.syyss+-  dM/               
   /     .yyyyyyy.     yMo.- syyyyyy.:yyyyyyo`.NN./ :yyyyyys-....`    oMy                
  :`    `syyyyyy:     +Mh`:  -syyyy:.yyyyy+- `dM/-..yyyyyyy-         :Mm`                
 .-     /yssssso     -NN./    `/oso-+o+/-`   sMs`: +ssssss:         `mM-                 
 :                  `mM:-.                  :Mm`/                   hM+                  
.-hdddddddddddddddddmMs -/dddddddmmmmdmmmmmmNN.`-ymmmmmmmmmmmmmmmmmmMh                   
  --------------------   .-------------------.   .---................`                   
                                                                                     
                  .-..................-:  :....-----........../                      
                  :        `::::::`   sm+:`    .:/+-++:.     -mh                     
                 :`      `:syyyyyo   :Mm--  `:syyy:-yyyy:   `mM:                     
                ..      -/syyyyys`  `mN::  -syyyy+`syyyys   yMo                      
               `:     -:./yyyyyy-   hM+:` /yyyyys`+yyyyyo  /Md                       
               :    .:. .yyyyyy+   +Mh-. /yyyyyy--yyyyyy: .NN.                       
              -.  .:-  `syyyyys`  -Nm-: `yyyyyy/`syyyyy/ `dM/                        
             `: `/:....+yyyyyy:` `mM::  -yyyyyo`oyyyys:  sMs                         
             :  `...../yyyyyy/.` yMo-`  `syyyy.:yyys+.  :Md`                         
            :`       `osssss+   /Mh.-    .+os/.oo+:.   .mN-                          
           .-         ``````   .NN.:       `````       hM+                           
           ::yyyyyyyyyyyyyyyyyymM/.:syyyyyyyyyyyyyyyyyhMy                            
            .+++++++/////////////  `+++++++++++++++/////`                            
                                                                                     
                                                                                     
"
end


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/dutch_top40/cli.rb', line 23

def menu       
        input = nil
        while input != 'exit'
            puts "Which song do you want more info on? Type list to see list again, type exit to quit.",""
            input = gets.strip.downcase
            case input.to_i
                when 1..@songs.size
                    puts "Current rank #{input}."
                    puts "#{@songs[input.to_i-1].title} - performing artist(s): #{@songs[input.to_i-1].name}"
                    puts "weeks in Top40: #{@songs[input.to_i-1].listed} - last weeks rank: #{@songs[input.to_i-1].last_weeks_rank}","" 
                else 
                    puts "Invalid input!" unless input == 'exit' || input == 'list'
                if input == 'list' 
                    print_songs
                end
                if input == 'exit' 
                    goodbye
                end
            end
        end
end


17
18
19
20
21
# File 'lib/dutch_top40/cli.rb', line 17

def print_songs
    @songs.each.with_index(1) do |song, index| 
        puts "#{index}.  #{song.title}"
    end
end