Class: BillboardHot100::CommandLineInteface

Inherits:
Object
  • Object
show all
Defined in:
lib/billboard_hot_100/command_line_interface.rb

Instance Method Summary collapse

Instance Method Details

#continueObject



73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/billboard_hot_100/command_line_interface.rb', line 73

def continue
  puts "\nWould you like information on another song? Enter Y or N\n"

  input = gets.strip.downcase
  case input
    when "y"
      ranges
    when "n", "exit"
      exit
    else
      invalid_choice
      continue
  end
end

#display_song(song) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/billboard_hot_100/command_line_interface.rb', line 88

def display_song(song)
  puts "\n#{song.rank}. #{song.title} by #{song.artist}"
  
  if song.last_week.length > 0 && !song.last_week.include?("-")
    puts "Last Week: #{song.last_week}"
  else
    puts "New To Chart!".colorize(:blue)
  end
  if song.peak_position.length > 0 
    puts "Peak Position: #{song.peak_position}"
  end
  if song.weeks_on_chart.length > 0 
    puts "Weeks On Chart: #{song.weeks_on_chart}"
  end
  if song.lyrics.length > 0
    puts "Lyrics: #{song.lyrics}"
  end
  if song.award.length > 0 
    puts "Award: #{song.award}".colorize(:blue)
  end
end

#display_songs(increment, input, low_num) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/billboard_hot_100/command_line_interface.rb', line 45

def display_songs(increment, input, low_num) 
  puts  "\nDisplaying songs #{low_num+1} through #{low_num+increment}\n\n"
  BillboardHot100::Song.all[low_num,increment].each do |song|
    puts "#{song.rank}. #{song.title} by #{song.artist}"
  end
  
  more_info(increment, input, low_num)
end

#exitObject



114
115
116
117
# File 'lib/billboard_hot_100/command_line_interface.rb', line 114

def exit
  puts "\nCheck back next week for the latest Billboard Hot 100!"
  exit!
end

#invalid_choiceObject



110
111
112
# File 'lib/billboard_hot_100/command_line_interface.rb', line 110

def invalid_choice
  puts "\nInvalid Choice, Please Try Again!".colorize(:red)
end

#more_info(increment, input, low_num) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/billboard_hot_100/command_line_interface.rb', line 54

def more_info(increment, input, low_num)
  puts "\nPlease enter the song you want more information on, or type LIST to select a new range of songs.\n"
  input = gets.strip
  
  case
    when input.to_i.between?(low_num+1,low_num+increment)
      song = BillboardHot100::Song.all[input.to_i-1]
      display_song(song)
    when input.downcase == "list"
      ranges
    when input.downcase == "exit"
      exit
    else
      puts "\nPlease enter a number between #{low_num+1} and #{low_num+increment}, or type LIST to select a new range of songs.\n".colorize(:red)
      display_songs(increment, input, low_num)
  end
  continue
end

#quantize_input(increment, total) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/billboard_hot_100/command_line_interface.rb', line 31

def quantize_input(increment, total)    
  input = gets.strip
  case  
    when input.to_i.between?(1,total)
      low_num = ((input.to_i-1)/increment).floor*increment
      display_songs(increment, input, low_num)
    when input.downcase == "exit"
      exit 
    else
      invalid_choice
      ranges
  end
end

#rangesObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/billboard_hot_100/command_line_interface.rb', line 13

def ranges
  puts "\nPlease enter the rankings you wish to see...\n\n"

  total = BillboardHot100::Song.all.size
  increment = 10
  ranges = total/increment
  ranking = 1
  ranges_s = ""

  ranges.times do
    ranges_s << "#{ranking}-#{ranking+increment-1}, "
    ranking += increment
  end
  puts ranges_s[0...-2]

  quantize_input(increment, total)
end

#runObject



3
4
5
6
# File 'lib/billboard_hot_100/command_line_interface.rb', line 3

def run
  BillboardHot100::Scraper.scrape_songs
  welcome
end

#welcomeObject



8
9
10
11
# File 'lib/billboard_hot_100/command_line_interface.rb', line 8

def welcome 
  puts "\nWelcome to the this weeks Billboard Hot 100!\n"
  ranges
end