Class: PitchforkReviews::CLI

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

Instance Method Summary collapse

Instance Method Details

#callObject



3
4
5
6
7
# File 'lib/pitchfork_reviews/cli.rb', line 3

def call
  list_reviews
  menu
  goodbye
end

#goodbyeObject



59
60
61
# File 'lib/pitchfork_reviews/cli.rb', line 59

def goodbye
  puts "Goodbye! Check back again soon for more new albums."
end

#list_reviewsObject



9
10
11
12
13
14
15
16
17
18
# File 'lib/pitchfork_reviews/cli.rb', line 9

def list_reviews
  puts
  puts "Welcome! Here are the most recent album reviews from Pitchfork."
  puts
  @albums = PitchforkReviews::Album.scrape_pitchfork
  @albums.each.with_index(1) do |album, i|
    puts "#{i}. #{album.name} by #{album.artist}#{album.best_new_album}"
  end
  puts
end


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/pitchfork_reviews/cli.rb', line 28

def menu
  input = nil
  while input != "exit"
    puts "Please enter the number of the album you would like to read more about."
    puts "Enter 'sort' to sort the albums by review score."
    puts "Enter 'list' to see the album list again."
    puts "Enter 'exit' to exit the program."
    input = gets.strip.downcase
    if input.to_i.between?(1,24)
      the_album = @albums[input.to_i-1]
      puts
      puts "#{the_album.name}"
      puts "by"
      puts "#{the_album.artist}"
      puts "#{the_album.genre}"
      puts
      puts "Score: #{the_album.score} #{the_album.best_new_album}"
      puts 
      puts "Summary:"
      puts "#{the_album.summary}"
      puts
      puts "Read the full review at http://pitchfork.com#{the_album.url}"
      puts
    elsif input == "list"
      list_reviews
    elsif input =="sort"
      sort_by_score
    end
  end
end

#sort_by_scoreObject



20
21
22
23
24
25
26
# File 'lib/pitchfork_reviews/cli.rb', line 20

def sort_by_score
  @albums = PitchforkReviews::Album.scrape_pitchfork
  @albums.sort! { |a,b| b.score <=> a.score}
  @albums.each.with_index(1) do |album, i|
    puts "#{i}. #{album.name} by #{album.artist}#{album.best_new_album}, #{album.score}"
  end
end