Module: Feedjira::FeedEntryUtilities

Constant Summary

Constants included from DateTimeUtilities

DateTimeUtilities::DATE_PARSERS

Instance Method Summary collapse

Instance Method Details

#[](field) ⇒ Object


66
67
68
# File 'lib/feedjira/feed_entry_utilities.rb', line 66

def [](field)
  instance_variable_get("@#{field}")
end

#[]=(field, value) ⇒ Object


70
71
72
# File 'lib/feedjira/feed_entry_utilities.rb', line 70

def []=(field, value)
  instance_variable_set("@#{field}", value)
end

#eachObject


53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/feedjira/feed_entry_utilities.rb', line 53

def each
  @rss_fields ||= instance_variables.map do |ivar|
    ivar.to_s.sub("@", "")
  end.select do |field| # rubocop:disable Style/MultilineBlockChain
    # select callable (public) methods only
    respond_to?(field)
  end

  @rss_fields.each do |field|
    yield(field, 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


24
25
26
# File 'lib/feedjira/feed_entry_utilities.rb', line 24

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

#publishedObject 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.


31
32
33
34
# File 'lib/feedjira/feed_entry_utilities.rb', line 31

def published=(val)
  parsed = parse_datetime(val)
  @published = parsed if parsed && (!@published || parsed < @published)
end

#sanitize!Object


43
44
45
46
47
48
49
# File 'lib/feedjira/feed_entry_utilities.rb', line 43

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.


38
39
40
41
# File 'lib/feedjira/feed_entry_utilities.rb', line 38

def updated=(val)
  parsed = parse_datetime(val)
  @updated = parsed if parsed && (!@updated || parsed > @updated)
end