Class: Pluto::Model::Feed
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Pluto::Model::Feed
- Includes:
- TextUtils::HypertextHelper
- Defined in:
- lib/pluto/models/feed.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#author_email ⇒ Object
alias(2) for email.
-
#author_name ⇒ Object
alias for author.
- #debug=(value) ⇒ Object
- #debug? ⇒ Boolean
-
#desc ⇒ Object
alias(2) for summary.
-
#description ⇒ Object
alias for summary.
-
#feed ⇒ Object
alias for feed_url.
- #feed_url ⇒ Object
- #feed_url? ⇒ Boolean
-
#link ⇒ Object
alias for url.
-
#match_terms?(terms, text) ⇒ Boolean
make helper method private - why? why not??.
-
#name ⇒ Object
attribute reader aliases.
-
#owner ⇒ Object
alias(3) for author.
-
#owner_name ⇒ Object
alias(2) for author.
- #published ⇒ Object
- #published? ⇒ Boolean
- #save_from_struct!(data) ⇒ Object
- #title ⇒ Object
- #title2 ⇒ Object
- #title2? ⇒ Boolean
- #title? ⇒ Boolean
- #touched? ⇒ Boolean
- #update_from_struct!(data) ⇒ Object
- #url ⇒ Object
- #url? ⇒ Boolean
Class Method Details
.latest ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/pluto/models/feed.rb', line 20 def self.latest # note: order by first non-null datetime field # coalesce - supported by sqlite (yes), postgres (yes) # note: if not published, touched or built use hardcoded 1971-01-01 for now ## order( "coalesce(published,touched,built,'1971-01-01') desc" ) order( "coalesce(feeds.last_published,'1971-01-01') desc" ) end |
Instance Method Details
#author_email ⇒ Object
alias(2) for email
43 |
# File 'lib/pluto/models/feed.rb', line 43 def () email; end |
#author_name ⇒ Object
alias for author
40 |
# File 'lib/pluto/models/feed.rb', line 40 def () ; end |
#debug=(value) ⇒ Object
74 |
# File 'lib/pluto/models/feed.rb', line 74 def debug=(value) @debug = value; end |
#debug? ⇒ Boolean
75 |
# File 'lib/pluto/models/feed.rb', line 75 def debug?() @debug || false; end |
#desc ⇒ Object
alias(2) for summary
36 |
# File 'lib/pluto/models/feed.rb', line 36 def desc() summary; end |
#description ⇒ Object
alias for summary
35 |
# File 'lib/pluto/models/feed.rb', line 35 def description() summary; end |
#feed ⇒ Object
alias for feed_url
38 |
# File 'lib/pluto/models/feed.rb', line 38 def feed() feed_url; end |
#feed_url ⇒ Object
55 |
# File 'lib/pluto/models/feed.rb', line 55 def feed_url() read_attribute_w_fallbacks( :feed_url, :auto_feed_url ); end |
#feed_url? ⇒ Boolean
50 |
# File 'lib/pluto/models/feed.rb', line 50 def feed_url?() read_attribute(:feed_url).present?; end |
#link ⇒ Object
alias for url
37 |
# File 'lib/pluto/models/feed.rb', line 37 def link() url; end |
#match_terms?(terms, text) ⇒ Boolean
make helper method private - why? why not??
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/pluto/models/feed.rb', line 78 def match_terms?( terms, text ) ### make helper method private - why? why not?? return false if text.blank? ## allow/guard against nil and empty string terms.each do |term| if /#{term}/i =~ text ## Note: lets ignore case (use i regex option) return true end end false # no term match found end |
#name ⇒ Object
attribute reader aliases
todo: check if we can use alias_method :name, :title - works for non-existing/on-demand-generated method too??
34 |
# File 'lib/pluto/models/feed.rb', line 34 def name() title; end |
#owner ⇒ Object
alias(3) for author
42 |
# File 'lib/pluto/models/feed.rb', line 42 def owner() ; end |
#owner_name ⇒ Object
alias(2) for author
41 |
# File 'lib/pluto/models/feed.rb', line 41 def owner_name() ; end |
#published ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/pluto/models/feed.rb', line 62 def published ## todo/fix: use a new name - do NOT squeeze convenience lookup into existing # db backed attribute read_attribute_w_fallbacks( :published, :touched, # try touched (aka updated (ATOM)) :built # try build (aka lastBuildDate (RSS)) ) end |
#published? ⇒ Boolean
58 |
# File 'lib/pluto/models/feed.rb', line 58 def published?() read_attribute(:published).present?; end |
#save_from_struct!(data) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/pluto/models/feed.rb', line 92 def save_from_struct!( data ) update_from_struct!( data ) data.items.each do |item| ###### ## check for filters (includes/excludes) if present ## for now just check for includes ## if includes.present? ## split terms (allow comma,pipe) - do NOT use space; allows e.g. terms such as github pages terms = includes.split( /\s*[,|]\s*/ ) ## remove leading and trailing white spaces - check - still required when using \s* ?? terms = terms.map { |term| term.strip } match = match_terms?( terms, item.title ) || match_terms?( terms, item.summary) || match_terms?( terms, item.content) if match == false puts "** SKIPPING | #{item.title}" puts " no include terms match: #{terms.join('|')}" next ## skip to next item end end item_rec = Item.find_by_guid( item.guid ) if item_rec.nil? item_rec = Item.new puts "** NEW | #{item.title}" else ## todo: check if any attribs changed puts "UPDATE | #{item.title}" end item_rec.debug = debug? ? true : false # pass along debug flag item_rec.update_from_struct!( self, item ) end # each item end |
#title ⇒ Object
53 |
# File 'lib/pluto/models/feed.rb', line 53 def title() read_attribute_w_fallbacks( :title, :auto_title ); end |
#title2 ⇒ Object
54 |
# File 'lib/pluto/models/feed.rb', line 54 def title2() read_attribute_w_fallbacks( :title2, :auto_title2 ); end |
#title2? ⇒ Boolean
49 |
# File 'lib/pluto/models/feed.rb', line 49 def title2?() read_attribute(:title2).present?; end |
#title? ⇒ Boolean
48 |
# File 'lib/pluto/models/feed.rb', line 48 def title?() read_attribute(:title).present?; end |
#touched? ⇒ Boolean
59 |
# File 'lib/pluto/models/feed.rb', line 59 def touched?() read_attribute(:touched).present?; end |
#update_from_struct!(data) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/pluto/models/feed.rb', line 134 def update_from_struct!( data ) ## todo: move to FeedUtils::Feed ??? why? why not?? if data.generator generator_full = '' generator_full << data.generator generator_full << " @version=#{data.generator_version}" if data.generator_version generator_full << " @uri=#{data.generator_uri}" if data.generator_uri else generator_full = nil end ## # todo: ## strip all tags from title2 ## limit to 255 chars ## e.g. title2 such as this exist ## This is a low-traffic announce-only list for people interested ## in hearing news about Polymer (<a href="http://polymer-project.org">http://polymer-project.org</a>). ## The higher-traffic mailing list for all kinds of discussion is ## <a href="https://groups.google.com/group/polymer-dev">https://groups.google.com/group/polymer-dev</a> feed_attribs = { format: data.format, published: data.published, touched: data.updated, built: data.built, summary: data.summary, ### todo/fix: add/use # auto_title: ???, # auto_url: ???, # auto_feed_url: ???, auto_title2: data.title2 ? (data.title2)[0...255] : data.title2, # limit to 255 chars; strip tags generator: generator_full } if debug? ## puts "*** dump feed_attribs:" ## pp feed_attribs puts "*** dump feed_attribs w/ class types:" feed_attribs.each do |key,value| puts " #{key}: >#{value}< : #{value.class.name}" end end update_attributes!( feed_attribs ) end |
#url ⇒ Object
52 |
# File 'lib/pluto/models/feed.rb', line 52 def url() read_attribute_w_fallbacks( :url, :auto_url ); end |
#url? ⇒ Boolean
47 |
# File 'lib/pluto/models/feed.rb', line 47 def url?() read_attribute(:url).present?; end |