Module: Feedjira::FeedEntryUtilities

Includes:
Enumerable
Included in:
Parser::AtomEntry, Parser::AtomFeedBurnerEntry, Parser::GoogleDocsAtomEntry, Parser::ITunesRSSItem, Parser::RSSEntry, Parser::RSSFeedBurnerEntry
Defined in:
lib/feedjira/feed_entry_utilities.rb

Instance Method Summary collapse

Instance Method Details

#[](field) ⇒ Object



57
58
59
# File 'lib/feedjira/feed_entry_utilities.rb', line 57

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

#[]=(field, value) ⇒ Object



61
62
63
# File 'lib/feedjira/feed_entry_utilities.rb', line 61

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

#eachObject



49
50
51
52
53
54
55
# File 'lib/feedjira/feed_entry_utilities.rb', line 49

def each
  @rss_fields ||= self.instance_variables

  @rss_fields.each do |field|
    yield(field.to_s.sub('@', ''), self.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



21
22
23
# File 'lib/feedjira/feed_entry_utilities.rb', line 21

def id
  @entry_id ||= @url
end

#parse_datetime(string) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/feedjira/feed_entry_utilities.rb', line 10

def parse_datetime(string)
  begin
    DateTime.parse(string).feed_utils_to_gm_time
  rescue
    warn "Failed to parse date #{string.inspect}"
    nil
  end
end

#publishedObject Also known as: last_modified



6
7
8
# File 'lib/feedjira/feed_entry_utilities.rb', line 6

def published
  @published ||= @updated
end

#published=(val) ⇒ Object

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



27
28
29
30
# File 'lib/feedjira/feed_entry_utilities.rb', line 27

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

#sanitize!Object



39
40
41
42
43
44
45
# File 'lib/feedjira/feed_entry_utilities.rb', line 39

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

#updated=(val) ⇒ Object

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



34
35
36
37
# File 'lib/feedjira/feed_entry_utilities.rb', line 34

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