Class: DeveloperNewsCliApp::CodeBurstScrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/developer_news_cli_app/CodeBurstScrapper.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/CodeBurstScrapper.rb', line 29

def self.article_count
  @@all.count
end

.articlesObject



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

def self.articles
  @@all
end

Instance Method Details

#get_articlesObject



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

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

#get_pageObject



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

def get_page
  Nokogiri::HTML(open("https://codeburst.io/"))
end

#make_articleObject



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/developer_news_cli_app/CodeBurstScrapper.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(".postMetaInline-authorLockup a").text
    a.date = article.css("time").text
    a.url = article.css("a").attribute("href").value
    a.website = "CodeBurst"
    a.trailing = article.search(".u-fontSize18").text == "" ? nil : article.search(".u-fontSize18").text
    @@all << a
  end
end