Class: WikiOnThisDay::Scraper::Homepage

Inherits:
WikiOnThisDay::Scraper show all
Defined in:
lib/wiki_on_this_day/homepage.rb

Instance Attribute Summary

Attributes inherited from WikiOnThisDay::Scraper

#html_doc

Instance Method Summary collapse

Constructor Details

#initializeHomepage

Returns a new instance of Homepage.



3
4
5
# File 'lib/wiki_on_this_day/homepage.rb', line 3

def initialize
  super('https://en.wikipedia.org/wiki/Main_Page')
end

Instance Method Details

#on_this_dayObject



7
8
9
10
11
12
13
14
15
16
# File 'lib/wiki_on_this_day/homepage.rb', line 7

def on_this_day
  events_hash = {}
  self.html_doc.css('div#mp-otd div#mp-otd-img + ul li').each do |event|
    events_hash[event.css('b a').text] = {}
    events_hash[event.css('b a').text][:year] = event.css('a').first.text
    events_hash[event.css('b a').text][:text] = event.children.text.split(/ – /)[1]
    events_hash[event.css('b a').text][:link_url] = 'https://en.wikipedia.org' + event.css('b a')[0]["href"]
  end
  events_hash
end