Class: Gandalf::Post

Inherits:
Object
  • Object
show all
Includes:
DataMapper::Resource
Defined in:
lib/gandalf/models.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse(feed) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/gandalf/models.rb', line 45

def Post.parse(feed)
  feed.entries.map do |entry|
    post = self.new({
      :title => entry.title,
      :link => entry.url,
      :author => entry.author,
      :description => entry.summary,
      :pub_date => entry.published.to_datetime,
      :cache_link => Digest::MD5.hexdigest(entry.url)
    })
  end
end

Instance Method Details

#clean!Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/gandalf/models.rb', line 33

def clean!
  self.title = self.title[0,255] if self.title
  if self.description
    self.description.gsub!(/\<[^\>]+\>|\n|&nbsp;/,' ')
    self.description.gsub!(/&gt;/,'<')
    self.description.gsub!(/&lt;/,'>')
    self.description.gsub!(/\s{2,}/,' ')
    self.description.strip!
    self.description = nil if self.description = ""
  end
end