Class: BirthYearAlbum::Album
- Inherits:
-
Object
- Object
- BirthYearAlbum::Album
- Defined in:
- lib/birth_year_album/album.rb
Instance Attribute Summary collapse
-
#artist ⇒ Object
Returns the value of attribute artist.
-
#name ⇒ Object
Returns the value of attribute name.
-
#year ⇒ Object
Returns the value of attribute year.
Class Method Summary collapse
-
.album_by_year(year) ⇒ Object
takes in a year and return the album information.
-
.get_page ⇒ Object
scapes wikipedia.
Instance Attribute Details
#artist ⇒ Object
Returns the value of attribute artist.
3 4 5 |
# File 'lib/birth_year_album/album.rb', line 3 def artist @artist end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/birth_year_album/album.rb', line 3 def name @name end |
#year ⇒ Object
Returns the value of attribute year.
3 4 5 |
# File 'lib/birth_year_album/album.rb', line 3 def year @year end |
Class Method Details
.album_by_year(year) ⇒ Object
takes in a year and return the album information.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/birth_year_album/album.rb', line 5 def self.album_by_year(year) #takes in a year and return the album information. page = self.get_page alb = self.new alb.year = year counter = 0 while counter <= page.css("tr td").length-1 #iterates through all tr td except the final one because it is nil. if page.css("tr td")[counter].text.to_i == alb.year #compares year on page to album year alb.artist = page.css("tr td")[counter+1].text.split("!")[1] #assign artist alb.name = page.css("tr td")[counter+3].text.split("!")[1] #assign album name end counter += 1 end alb end |
.get_page ⇒ Object
scapes wikipedia
22 23 24 |
# File 'lib/birth_year_album/album.rb', line 22 def self.get_page #scapes wikipedia doc = Nokogiri::HTML(open("https://en.wikipedia.org/wiki/List_of_best-selling_albums_by_year_in_the_United_States")) end |