Module: Feedjira::FeedEntryUtilities

Constant Summary

Constants included from DateTimeUtilities

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

#eachObject



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

#idObject

Returns the id of the entry or its url if not id is present, as some formats don't support it rubocop:disable Naming/MemoizedInstanceVariableName



22
23
24
# File 'lib/feedjira/feed_entry_utilities.rb', line 22

def id
  @entry_id ||= @url
end

#parse_datetime(string) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/feedjira/feed_entry_utilities.rb', line 10

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.warn(e)
  nil
end

#publishedObject Also known as: last_modified



6
7
8
# File 'lib/feedjira/feed_entry_utilities.rb', line 6

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 parsed && (!@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 parsed && (!@updated || parsed > @updated)
end