Module: Bnm::CLI

Defined in:
lib/bnm/cli.rb

Class Method Summary collapse

Class Method Details

.artist_page(input, index, artists) ⇒ Object

DISPLAYS ARTIST PAGE####################



45
46
47
48
49
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
84
85
86
87
88
89
90
# File 'lib/bnm/cli.rb', line 45

def self.artist_page(input, index, artists)
  url = artists[index][:listen]
  artist = Array.new
  artist.push(" #{artists[index][:score]}".red)
  artist.push(" #{artists[index][:name]}".yellow)
  artist.push(" #{artists[index][:album]}".green)

  puts artist.join('')
  puts "--------------------------------------------------------".yellow
  puts "1 for Apple Music"
  puts "2 for article"
  puts "3 for Amoeba Music"
  puts "4 to re-list"
  puts "5 to exit"
  input = gets.chomp

  if input == '1' && !artists[index][:itunes].nil?
    system('open', artists[index][:itunes])
    puts '########################################################'.yellow
    artist_page(input, index, artists)
  elsif input == '1' && artists[index][:itunes].nil?
    puts '########################################################'.yellow
    puts 'There is no link available. Please choose another option'.red
    puts '########################################################'.yellow
    artist_page(input, index, artists)
  elsif input == '2'
     puts "#{artists[index][:editorial]}"
     puts '########################################################'.yellow
     artist_page(input, index, artists)
   elsif input == '3' && !url.nil?
      system('open', url)
      puts '########################################################'.yellow
      artist_page(input, index, artists)
    elsif input == '3' && url.nil?
      puts '########################################################'.yellow
      puts 'There is no link available. Please choose another option'.red
      puts '########################################################'.yellow
      artist_page(input, index, artists)
    elsif input == '4'
      launch(artists)
    elsif input == '5'
      exit
    else
      launch(artists)
  end
end

.display_artist(artists) ⇒ Object

DISPLAYS ARTIST UPON GEM LAUNCH######



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

def self.display_artist(artists)
  counter = 1
  artists.each do |i|
    display = Array.new
    display.push(" #{i[:score]}".red)
    display.push(" #{i[:name]}".yellow)
    display.push(" #{i[:album]}".green)
    printf("%2d. %5s\n", counter, display.join(''))
    counter += 1
  end
  puts "--------------------------------".yellow
  puts 'Please chose an artist by number'
  puts "--------------------------------".yellow
end

.launch(artists) ⇒ Object

INIT. INTERFACE #############################



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/bnm/cli.rb', line 5

def self.launch(artists)
  puts "---------------------------------------------------------------".yellow
  puts "    WELCOME TO PITCHFORK'S 'BEST NEW MUSIC' SORTED BY SCORE.   "
  puts "         SELECT AN ARTIST BY NUMBER. NOW WITH APPLE MUSIC      "
  puts "                  OR PRESS ANY LETTER TO EXIT                  "
  puts "---------------------------------------------------------------".yellow
  display_artist(artists)

  input = Integer(gets.chomp) rescue nil

  if input == nil
    exit
  elsif input < 1 || input > 24
    puts '###############################################'.yellow
    puts 'THAT IS NOT A VALID CHOICE, PLEASE CHOOSE AGAIN'.red
    puts '###############################################'.yellow
    launch(artists)
  else
    index = input - 1
    artist_page(input, index, artists)
  end
end