Class: DeveloperNewsCliApp::HackerNoonScrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/developer_news_cli_app/HackerNoonScrapper.rb

Constant Summary collapse

@@all =
[]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.article_countObject



29
30
31
# File 'lib/developer_news_cli_app/HackerNoonScrapper.rb', line 29

def self.article_count
	@@all.count
end

.articlesObject



25
26
27
# File 'lib/developer_news_cli_app/HackerNoonScrapper.rb', line 25

def self.articles
	@@all
end

Instance Method Details

#get_articlesObject



8
9
10
# File 'lib/developer_news_cli_app/HackerNoonScrapper.rb', line 8

def get_articles
	self.get_page.css(".js-trackedPost")
end

#get_pageObject



4
5
6
# File 'lib/developer_news_cli_app/HackerNoonScrapper.rb', line 4

def get_page
	Nokogiri::HTML(open("https://hackernoon.com/"))
end

#make_articleObject



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/developer_news_cli_app/HackerNoonScrapper.rb', line 12

def make_article
	self.get_articles.each do |article|
		a = DeveloperNewsCliApp::Article.new
		a.title = article.css("h3").text
		a.author = article.css(".ds-link").text
		a.date = article.css("time").text
		a.url = article.css("a").attribute("href").value
		a.website = "HackerNoon"
		a.trailing = article.css(".u-fontSize18").text == "" ? nil : article.css(".u-fontSize18").text
		@@all << a
	end
end