Module: Feedzirra::FeedEntryUtilities

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

Instance Method Summary collapse

Instance Method Details

#[](field) ⇒ Object



56
57
58
# File 'lib/feedzirra/feed_entry_utilities.rb', line 56

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

#[]=(field, value) ⇒ Object



60
61
62
# File 'lib/feedzirra/feed_entry_utilities.rb', line 60

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

#eachObject



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

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/feedzirra/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/feedzirra/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/feedzirra/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/feedzirra/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
# File 'lib/feedzirra/feed_entry_utilities.rb', line 39

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

#updated=(val) ⇒ Object

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



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

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