Class: WikiOnThisDay::Scraper::Homepage

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

Instance Attribute Summary collapse

Attributes inherited from WikiOnThisDay::Scraper

#html_doc

Instance Method Summary collapse

Constructor Details

#initializeHomepage

Returns a new instance of Homepage.



5
6
7
8
9
10
11
# File 'lib/wiki_on_this_day/homepage.rb', line 5

def initialize
  super('https://en.wikipedia.org/wiki/Main_Page')
  @snippets = Array.new
  self.html_doc.search('div#mp-otd div#mp-otd-img + ul li').each do |event|
    @snippets << WikiOnThisDay::Snippet.new(year: event.css('a').first.text, text: event.children.text.split(//)[1], link_url: 'https://en.wikipedia.org' + event.css('b a')[0]["href"])
  end
end

Instance Attribute Details

#snippetsObject

Returns the value of attribute snippets.



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

def snippets
  @snippets
end

Instance Method Details

#summarizeObject



13
14
15
# File 'lib/wiki_on_this_day/homepage.rb', line 13

def summarize
  self.snippets.each { |snippet| snippet.print }
end