Class: Scraper
- Inherits:
-
Object
- Object
- Scraper
- Defined in:
- lib/scraper.rb
Instance Attribute Summary collapse
-
#doc ⇒ Object
readonly
Returns the value of attribute doc.
-
#newspaper ⇒ Object
readonly
Returns the value of attribute newspaper.
Instance Method Summary collapse
- #articles ⇒ Object
- #category ⇒ Object
- #content(article) ⇒ Object
- #create_articles ⇒ Object
-
#initialize ⇒ Scraper
constructor
A new instance of Scraper.
- #title(article) ⇒ Object
Constructor Details
Instance Attribute Details
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
7 8 9 |
# File 'lib/scraper.rb', line 7 def doc @doc end |
#newspaper ⇒ Object (readonly)
Returns the value of attribute newspaper.
7 8 9 |
# File 'lib/scraper.rb', line 7 def newspaper @newspaper end |
Instance Method Details
#articles ⇒ Object
14 15 16 |
# File 'lib/scraper.rb', line 14 def articles @doc.css("article.teaser") end |
#category ⇒ Object
26 27 28 |
# File 'lib/scraper.rb', line 26 def category @doc.css("h1.simple-header__name").text end |
#content(article) ⇒ Object
22 23 24 |
# File 'lib/scraper.rb', line 22 def content(article) article.css("div.teaser__text").text end |
#create_articles ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/scraper.rb', line 30 def create_articles cat = category articles.each do |x| article = Article.new(title(x)) article.category = cat article.content = content(x) @newspaper.add_article(article) end end |
#title(article) ⇒ Object
18 19 20 |
# File 'lib/scraper.rb', line 18 def title(article) article.css("span.flytitle-and-title__title").text end |