Module: Feedjira::FeedEntryUtilities
Constant Summary
DateTimeUtilities::DATE_PARSERS
Instance Method Summary
collapse
Instance Method Details
#[](field) ⇒ Object
59
60
61
|
# File 'lib/feedjira/feed_entry_utilities.rb', line 59
def [](field)
instance_variable_get("@#{field}")
end
|
#[]=(field, value) ⇒ Object
63
64
65
|
# File 'lib/feedjira/feed_entry_utilities.rb', line 63
def []=(field, value)
instance_variable_set("@#{field}", value)
end
|
#each ⇒ Object
51
52
53
54
55
56
57
|
# File 'lib/feedjira/feed_entry_utilities.rb', line 51
def each
@rss_fields ||= instance_variables
@rss_fields.each do |field|
yield(field.to_s.sub('@', ''), instance_variable_get(field))
end
end
|
#id ⇒ Object
Returns the id of the entry or its url if not id is present, as some formats don’t support it
23
24
25
|
# File 'lib/feedjira/feed_entry_utilities.rb', line 23
def id
@entry_id ||= @url
end
|
#parse_datetime(string) ⇒ Object
12
13
14
15
16
17
18
|
# File 'lib/feedjira/feed_entry_utilities.rb', line 12
def parse_datetime(string)
DateTime.parse(string).feed_utils_to_gm_time
rescue StandardError => e
Feedjira.logger.warn { "Failed to parse date #{string.inspect}" }
Feedjira.logger.debug(e)
nil
end
|
#published ⇒ Object
Also known as:
last_modified
8
9
10
|
# File 'lib/feedjira/feed_entry_utilities.rb', line 8
def published
@published ||= @updated
end
|
#published=(val) ⇒ Object
Writer for published. By default, we keep the “oldest” publish time found.
29
30
31
32
|
# File 'lib/feedjira/feed_entry_utilities.rb', line 29
def published=(val)
parsed = parse_datetime(val)
@published = parsed if !@published || parsed < @published
end
|
#sanitize! ⇒ Object
41
42
43
44
45
46
47
|
# File 'lib/feedjira/feed_entry_utilities.rb', line 41
def sanitize!
%w(title author summary content image).each do |name|
if respond_to?(name) && send(name).respond_to?(:sanitize!)
send(name).send :sanitize!
end
end
end
|
#updated=(val) ⇒ Object
Writer for updated. By default, we keep the most recent update time found.
36
37
38
39
|
# File 'lib/feedjira/feed_entry_utilities.rb', line 36
def updated=(val)
parsed = parse_datetime(val)
@updated = parsed if !@updated || parsed > @updated
end
|