Sha256: 1c44ebd31b0ea3d62a9e6a6672997aab7ee9b98c988a99e79f26def7063246f2

Contents?: true

Size: 1.15 KB

Versions: 3

Compression:

Stored size: 1.15 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  
      @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!
      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

3 entries across 3 versions & 1 rubygems

Version Path
feedzirra-0.1.0 lib/feedzirra/feed_entry_utilities.rb
feedzirra-0.0.31 lib/feedzirra/feed_entry_utilities.rb
feedzirra-0.0.30 lib/feedzirra/feed_entry_utilities.rb