9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/simpsons_world/scrape.rb', line 9
def self.all
doc = Nokogiri::HTML(open BASE_URL << EPISODES_URL)
seasons = doc.css(".chapters-wrapper")
seasons.each_with_index do |season, i|
number = season.attr 'data-season-number'
episodes = season.css("ul.items > li").map.with_index(1) { |episode, j|
[ j,
{
title: episode.css('.category-thumb-expanded .thumbnail-text').text,
description: clean_description(episode.css('.category-thumb-expanded .thumbnail-extra-text').text),
url: episode.css('a')[0]['href']
}
]
}.to_h
SimpsonsWorld::Season.new(number, episodes)
end
end
|