Sha256: c7fbc8c84db3a5deaf95f05dd2aeb8acecbe565d982b76f18a6c9fff8ed934b9

Contents?: true

Size: 1.3 KB

Versions: 7

Compression:

Stored size: 1.3 KB

Contents

module Feedzirra
  module FeedEntryUtilities    
    def published
      @published || @updated
    end
    
    def parse_datetime(string)
      begin
        DateTime.parse(string).feed_utils_to_gm_time
      rescue
        puts "DATE CAN'T BE PARSED: #{string}"
        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
      @id || @url
    end
    
    def new_entry?
      @_new_entry.nil? ? true : @_new_entry
    end
    
    def mark_old!
      @_new_entry = false
    end

    def mark_new!
      @_new_entry = true
    end
    
    ##
    # Writter 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
    
    ##
    # Writter 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!
      self.title.sanitize!   if self.title
      self.author.sanitize!  if self.author
      self.summary.sanitize! if self.summary
      self.content.sanitize! if self.content
    end
    
    alias_method :last_modified, :published
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
jsl-feedzirra-0.0.12.10 lib/feedzirra/parser/feed_entry_utilities.rb
jsl-feedzirra-0.0.12.12 lib/feedzirra/parser/feed_entry_utilities.rb
jsl-feedzirra-0.0.12.5 lib/feedzirra/parser/feed_entry_utilities.rb
jsl-feedzirra-0.0.12.6 lib/feedzirra/parser/feed_entry_utilities.rb
jsl-feedzirra-0.0.12.7 lib/feedzirra/parser/feed_entry_utilities.rb
jsl-feedzirra-0.0.12.8 lib/feedzirra/parser/feed_entry_utilities.rb
jsl-feedzirra-0.0.12.9 lib/feedzirra/parser/feed_entry_utilities.rb