Sha256: e40d71a58d7caf7b0a9a9f17a9579c0c397686b7917db787a223720141b849b1

Contents?: true

Size: 1.51 KB

Versions: 7

Compression:

Stored size: 1.51 KB

Contents

module Feedzirra
  module FeedEntryUtilities

    include Enumerable

    def published
      @published ||= @updated
    end

    def parse_datetime(string)
      begin
        DateTime.parse(string).feed_utils_to_gm_time
      rescue
        warn "Failed to parse date #{string.inspect}"
        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

    ##
    # Writer 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

    ##
    # Writer for updated. By default, we keep the most recent update time found.
    def updated=(val)
      parsed = parse_datetime(val)
      @updated = parsed if !@updated || parsed > @updated
    end

    def sanitize!
      %w[title author summary content image].each do |name|
        if self.respond_to?(name) && self.send(name).respond_to?(:sanitize!)
          self.send(name).send :sanitize!
        end
      end
    end

    alias_method :last_modified, :published

    def each
      @rss_fields ||= self.instance_variables

      @rss_fields.each do |field|
        yield(field.to_s.sub('@', ''), self.instance_variable_get(field))
      end
    end

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

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

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
feedzirra-0.7.1 lib/feedzirra/feed_entry_utilities.rb
feedzirra-0.7.0 lib/feedzirra/feed_entry_utilities.rb
feedzirra-0.6.0 lib/feedzirra/feed_entry_utilities.rb
feedzirra-0.5.0 lib/feedzirra/feed_entry_utilities.rb
feedzirra-0.4.0 lib/feedzirra/feed_entry_utilities.rb
feedzirra-0.3.0 lib/feedzirra/feed_entry_utilities.rb
feedzirra-0.2.2 lib/feedzirra/feed_entry_utilities.rb