/
feed_entry_utilities.rb
45 lines (39 loc) · 1.15 KB
/
feed_entry_utilities.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
module Feedzirra
module FeedEntryUtilities
def published
@published || @updated
end
def parse_datetime(string)
begin
DateTime.parse(string).feed_utils_to_gm_time
rescue
puts "DATE CAN'T BE PARSED: #{string}"
nil
end
end
##
# Returns the id of the entry or its url if not id is present, as some formats don't support it
def id
@entry_id || @url
end
##
# Writter for published. By default, we keep the "oldest" publish time found.
def published=(val)
parsed = parse_datetime(val)
@published = parsed if !@published || parsed < @published
end
##
# Writter for udapted. By default, we keep the most recenet update time found.
def updated=(val)
parsed = parse_datetime(val)
@updated = parsed if !@updated || parsed > @updated
end
def sanitize!
self.title.sanitize! if self.title
self.author.sanitize! if self.author
self.summary.sanitize! if self.summary
self.content.sanitize! if self.content
end
alias_method :last_modified, :published
end
end