class SimpsonsWorld::Scrape

Public Class Methods

all() click to toggle source
# 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
clean_description(str) click to toggle source
# File lib/simpsons_world/scrape.rb, line 27
def self.clean_description str
  str.gsub(/SEASON PREMIERE\.|Presented by FXX\./i, '').strip
end