Class: BillboardTop100

Inherits:
Object
  • Object
show all
Defined in:
lib/billboard-top-100.rb

Instance Method Summary collapse

Instance Method Details

#getArtist100(date = "") ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/billboard-top-100.rb', line 39

def getArtist100(date = "")
url = 'http://www.billboard.com/charts/artist-100'
if date.length > 0
	url += '/' + date
end
  artists = []
names = []
images = []
page = HTTParty.get(url)
parser = Nokogiri::HTML(page)
parser.css('.chart-row__artist').each do |artist|
	names.push(artist.text.to_s.squeeze(" ")[1..artist.to_s.length - 1].gsub("\n", ""))
end
parser.css('.chart-row__image').each do |image|
	if image.to_s.include? 'background-image'
		images.push(image.to_s.split('url(')[1].to_s.split(')')[0])
	else
		images.push(image.to_s.split('imagesrc="')[1].to_s.split('">')[0])
	end
end
for i in 0..99
	artist = Artist.new(names[i], i + 1, images[i])
	artists[i] = artist
end
return artists
end

#getBillboard200(date = "") ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/billboard-top-100.rb', line 66

def getBillboard200(date = "")
url = 'http://www.billboard.com/charts/billboard-200'
if date.length > 0
	url += '/' + date
end
  albums = []
  artists = []
titles = []
images = []
page = HTTParty.get(url)
parser = Nokogiri::HTML(page)
parser.css('.chart-row__song').each do |title|
	titles.push(title.text.to_s.squeeze(" ")[0..title.to_s.length - 1].gsub("\n", ""))
end
parser.css('.chart-row__artist').each do |artist|
	artists.push(artist.text.to_s.squeeze(" ")[1..artist.to_s.length - 1].gsub("\n", ""))
end
parser.css('.chart-row__image').each do |image|
	if image.to_s.include? 'background-image'
		images.push(image.to_s.split('url(')[1].to_s.split(')')[0])
	else
		images.push(image.to_s.split('imagesrc="')[1].to_s.split('">')[0])
	end
end
for i in 0..199
	album = Album.new(titles[i], artists[i], i + 1, images[i])
	albums[i] = album
end
return albums
end

#getTop100(date = "") ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/billboard-top-100.rb', line 8

def getTop100(date = "")
	url = 'http://www.billboard.com/charts/hot-100'
	if date.length > 0
		url += '/' + date
	end
	tracks = []
	titles = []
	artists = []
	covers = []
	page = HTTParty.get(url)
	parser = Nokogiri::HTML(page)
	parser.css('.chart-row__song').each do |title|
		titles.push(title.text)
	end
	parser.css('.chart-row__artist').each do |artist|
		artists.push(artist.text.to_s.squeeze(" ")[1..artist.to_s.length - 1].gsub("\n", ""))
	end
	parser.css('.chart-row__image').each do |cover|
		if cover.to_s.include? 'background-image'
			covers.push(cover.to_s.split('url(')[1].to_s.split(')')[0])
		else
			covers.push(cover.to_s.split('imagesrc="')[1].to_s.split('">')[0])
		end
	end
	for i in 0..99
		track = Track.new(titles[i], artists[i], i + 1, covers[i])
		tracks[i] = track
	end
	return tracks
end