Class: DeveloperNewsCliApp::AListApartScrapper

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

Constant Summary collapse

@@all =
[]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.article_countObject



28
29
30
# File 'lib/developer_news_cli_app/AListApartScrapper.rb', line 28

def self.article_count
	@@all.count
end

.articlesObject



24
25
26
# File 'lib/developer_news_cli_app/AListApartScrapper.rb', line 24

def self.articles
	@@all
end

Instance Method Details

#get_articlesObject



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

def get_articles
	self.get_page.css(".entry-list")
end

#get_pageObject



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

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

#make_articleObject



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

def make_article
	self.get_articles.each do |article|
		a = DeveloperNewsCliApp::Article.new
		a.title = article.css(".entry-title a").text
		a.author = article.css(".author").text
		a.date = article.css("time").text
		a.trailing = article.css("p")[1].text
		a.url = "https://alistapart.com" + article.css(".entry-title a").attribute("href").value
		@@all << a
	end
end