module Feedjira::FeedEntryUtilities

Public Instance Methods

[](field) click to toggle source
# File lib/feedjira/feed_entry_utilities.rb, line 66
def [](field)
  instance_variable_get("@#{field}")
end
[]=(field, value) click to toggle source
# File lib/feedjira/feed_entry_utilities.rb, line 70
def []=(field, value)
  instance_variable_set("@#{field}", value)
end
each() { |field, instance_variable_get(:"@#{field}")| ... } click to toggle source
# 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
id() click to toggle source

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

# File lib/feedjira/feed_entry_utilities.rb, line 24
def id
  @entry_id ||= @url
end
last_modified()
Alias for: published
parse_datetime(string) click to toggle source
# 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
published() click to toggle source
# File lib/feedjira/feed_entry_utilities.rb, line 8
def published
  @published ||= @updated
end
Also aliased as: last_modified
published=(val) click to toggle source

Writer for published. By default, we keep the “oldest” publish time found.

# 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!() click to toggle source
# 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) click to toggle source

Writer for updated. By default, we keep the most recent update time found.

# File lib/feedjira/feed_entry_utilities.rb, line 38
def updated=(val)
  parsed = parse_datetime(val)
  @updated = parsed if parsed && (!@updated || parsed > @updated)
end