Module: Feedzirra::FeedEntryUtilities
- Includes:
- Enumerable
- Included in:
- Parser::AtomEntry, Parser::AtomFeedBurnerEntry, Parser::ITunesRSSItem, Parser::RSSEntry, Parser::RSSFeedBurnerEntry
- Defined in:
- lib/feedzirra/feed_entry_utilities.rb
Instance Method Summary collapse
- #[](field) ⇒ Object
- #[]=(field, value) ⇒ Object
- #each ⇒ Object
-
#id ⇒ Object
Returns the id of the entry or its url if not id is present, as some formats don’t support it.
- #parse_datetime(string) ⇒ Object
- #published ⇒ Object (also: #last_modified)
-
#published=(val) ⇒ Object
Writer for published.
- #sanitize! ⇒ Object
-
#updated=(val) ⇒ Object
Writer for updated.
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 |
#each ⇒ Object
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 |
#id ⇒ Object
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 puts "DATE CAN'T BE PARSED: [#{string}]" nil end end |
#published ⇒ Object 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..sanitize! if self. 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 |