class Mmonews::Article
Attributes
content[RW]
date_published[RW]
source[RW]
summary[RW]
title[RW]
url[RW]
Public Class Methods
all()
click to toggle source
# File lib/mmonews/article.rb, line 12 def self.all @@all end
count()
click to toggle source
# File lib/mmonews/article.rb, line 28 def self.count self.all.length end
create(article_hash)
click to toggle source
# File lib/mmonews/article.rb, line 20 def self.create(article_hash) self.new(article_hash).tap{ |s| s.save } end
find(id)
click to toggle source
# File lib/mmonews/article.rb, line 24 def self.find(id) self.all[id - 1] end
new(article_attributes)
click to toggle source
# File lib/mmonews/article.rb, line 8 def initialize(article_attributes) article_attributes.each{ |key, value| send("#{key}=", value) } end
print_articles()
click to toggle source
# File lib/mmonews/article.rb, line 38 def self.print_articles self.all.each_with_index do |article, i| puts "#{i+1}. #{article.title}" puts "\t#{article.author} - #{article.date_published} - #{article.source}" puts "#{article.summary}\n" end end
Public Instance Methods
fetch_article()
click to toggle source
# File lib/mmonews/article.rb, line 32 def fetch_article data = Mmonews::Scraper.new(url).document self.content = data.search('div.commonContent').text.strip.gsub(/[\t\r\n]/, '') self end
print_full()
click to toggle source
# File lib/mmonews/article.rb, line 46 def print_full puts self.title puts "\t#{self.author} - #{self.date_published} - #{self.source}" puts self.content end
save()
click to toggle source
# File lib/mmonews/article.rb, line 16 def save self.class.all << self end