class DeveloperNewsCliApp::FreeCodeCampScrapper
Public Class Methods
article_count()
click to toggle source
# File lib/developer_news_cli_app/FreeCodeCampScrapper.rb, line 31 def self.article_count @@all.count end
articles()
click to toggle source
# File lib/developer_news_cli_app/FreeCodeCampScrapper.rb, line 27 def self.articles @@all end
Public Instance Methods
get_articles()
click to toggle source
# File lib/developer_news_cli_app/FreeCodeCampScrapper.rb, line 8 def get_articles self.get_page.css(".postArticle") end
get_page()
click to toggle source
# File lib/developer_news_cli_app/FreeCodeCampScrapper.rb, line 4 def get_page Nokogiri::HTML(open("https://medium.freecodecamp.org/")) end
make_article()
click to toggle source
# File lib/developer_news_cli_app/FreeCodeCampScrapper.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.read_time = article.css(".readingTime").attribute("title").value a.url = article.css(".postArticle-readMore a").attribute("href").value a.website = "FreeCodeCamp" a.subtitle = article.css("h4").text == "" ? nil : article.css("h4").text a.trailing = article.css("p").text == "" ? nil : article.css("p").text @@all << a end end