Class: Album

Inherits:
Object
  • Object
show all
Defined in:
lib/best_music/album.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, artist, genre, url) ⇒ Album

Returns a new instance of Album.



8
9
10
11
12
13
14
15
# File 'lib/best_music/album.rb', line 8

def initialize(name, artist, genre, url)
  @name = name
  @artist = artist
  @genre = genre
  @url = url
  Genre.all.each {|g| g.albums << self if g.name == genre}
  self.class.all << self
end

Instance Attribute Details

#artistObject

Returns the value of attribute artist.



4
5
6
# File 'lib/best_music/album.rb', line 4

def artist
  @artist
end

#descriptionObject

Returns the value of attribute description.



4
5
6
# File 'lib/best_music/album.rb', line 4

def description
  @description
end

#genreObject

Returns the value of attribute genre.



4
5
6
# File 'lib/best_music/album.rb', line 4

def genre
  @genre
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/best_music/album.rb', line 4

def name
  @name
end

#ratingObject

Returns the value of attribute rating.



4
5
6
# File 'lib/best_music/album.rb', line 4

def rating
  @rating
end

#urlObject

Returns the value of attribute url.



4
5
6
# File 'lib/best_music/album.rb', line 4

def url
  @url
end

Class Method Details

.albums_by_ratingObject



21
22
23
# File 'lib/best_music/album.rb', line 21

def self.albums_by_rating
  all.sort_by {|a| a.rating}.reverse
end

.allObject



17
18
19
# File 'lib/best_music/album.rb', line 17

def self.all
  @@all
end