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

#display_song(song) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/billboard_hot_100/command_line_interface.rb', line 64

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(:red)
    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(:red)
    end
end

#display_songs(input) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/billboard_hot_100/command_line_interface.rb', line 22

def display_songs(input)
  case input
    when 1..100
      increment = 10
      quantize(input, increment)
    else
      invalid_choice
  end
end

#display_ten_songs(low_num) ⇒ Object



37
38
39
40
41
42
# File 'lib/billboard_hot_100/command_line_interface.rb', line 37

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

#goodbyeObject



85
86
87
88
# File 'lib/billboard_hot_100/command_line_interface.rb', line 85

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

#invalid_choiceObject



90
91
92
93
# File 'lib/billboard_hot_100/command_line_interface.rb', line 90

def invalid_choice
  puts "\nInvalid Choice!"
  run
end

#list_rangesObject



15
16
17
18
19
20
# File 'lib/billboard_hot_100/command_line_interface.rb', line 15

def list_ranges
  puts "\nPlease enter the rankings you wish to see...\n"
  puts "\nEnter 1-10, 11-20, 21-30, 31-40, 41-50, 51-60, 61-70, 71-80, 81-90 or 91-100\n"
  input = gets.strip.to_i
  display_songs(input)
end

#more_infoObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/billboard_hot_100/command_line_interface.rb', line 44

def more_info
    puts "\nPlease enter the song you want more information on.\n"
    input = gets.strip
    
    song = BillboardHot100::Song.all[input.to_i-1]

    display_song(song)

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

    input = gets.strip.downcase
    if input == "y"
      run
    elsif input == "n"
      goodbye
    else
      invalid_choice
    end
end

#quantize(input, increment) ⇒ Object



32
33
34
35
# File 'lib/billboard_hot_100/command_line_interface.rb', line 32

def quantize(input, increment)
  low_num = ((input-1)/increment).floor*increment
  display_ten_songs(low_num)
end

#runObject



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

def run
  BillboardHot100::Scraper.scrape_songs
  welcome
  list_ranges
  more_info
  goodbye
end

#welcomeObject



11
12
13
# File 'lib/billboard_hot_100/command_line_interface.rb', line 11

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