Class: PolyrexFeedReader
- Inherits:
-
Object
- Object
- PolyrexFeedReader
- Defined in:
- lib/polyrex-feed-reader.rb
Instance Method Summary collapse
- #feed_count ⇒ Object
- #feeds_to_html ⇒ Object
- #fetch_feeds ⇒ Object
-
#initialize(polyrex) ⇒ PolyrexFeedReader
constructor
A new instance of PolyrexFeedReader.
- #refresh ⇒ Object (also: #update_doc)
- #save_css(filepath = 'feeds.css') ⇒ Object
- #save_html(filepath = 'feeds.html') ⇒ Object
- #save_latestnews(filename = 'latest.html') ⇒ Object
- #save_opml(filepath = 'feeds.opml') ⇒ Object
- #save_xml(filepath = 'feeds.xml') ⇒ Object
Constructor Details
#initialize(polyrex) ⇒ PolyrexFeedReader
Returns a new instance of PolyrexFeedReader.
27 28 29 30 31 |
# File 'lib/polyrex-feed-reader.rb', line 27 def initialize(polyrex) @polyrex = polyrex end |
Instance Method Details
#feed_count ⇒ Object
33 34 35 |
# File 'lib/polyrex-feed-reader.rb', line 33 def feed_count() @polyrex.xpath 'count(records/column/records/section/records/feed)' end |
#feeds_to_html ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/polyrex-feed-reader.rb', line 37 def feeds_to_html() feeds do |feed, filename| next if nothing_new? feed puts "transforming %s " % filename xsltproc 'dynarex-feed.xsl', File.read(filename), filename.sub(/xml$/,'html') end end |
#fetch_feeds ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/polyrex-feed-reader.rb', line 47 def fetch_feeds() feeds do |feed, filename| next if nothing_new? feed puts "fetching %s " % feed.rss_url.inspect rtd = RSStoDynarex.new feed.rss_url dynarex = rtd.to_dynarex dynarex.save(filename) do |xml| a = xml.lines.to_a line1 = a.shift a.unshift %Q{<?xml-stylesheet title="XSL_formatting" type="text/xsl" href="dynarex-feed.xsl"?>\n} a.unshift W3CENTITIES a.unshift line1 a.join end end end |
#refresh ⇒ Object Also known as: update_doc
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 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 |
# File 'lib/polyrex-feed-reader.rb', line 72 def refresh @datetimestamp = () feeds do |feed, filename| d = Dynarex.new filename feed.last_accessed = @datetimestamp feed.last_modified = @datetimestamp if feed.last_modified.empty? feed.xhtml = filename items = d.to_h[0..2] if feed.records.length > 0 and \ items.first[:title] == feed.item[0].title then feed.recent = recency(feed.last_modified) next end puts 'adding : ' + filename.inspect feed.recent = 'a_hot' feed.records.remove_all items.each.with_index do |x, i| h = { title: x[:title], link: x[:link], local_link: "%s#%s" % [filename.sub(/xml$/,'html'),i] } if i == 0 and feed.important != 'n' then raw_desc = CGI.unescapeHTML(x[:description]).gsub(/<\/?[^>]*>/, "") desc = raw_desc.length > 300 ? raw_desc[0..296] + ' ...' : raw_desc h[:description] = desc end feed.create.item h end feed.last_modified = @datetimestamp end end |
#save_css(filepath = 'feeds.css') ⇒ Object
121 122 123 124 125 126 127 128 |
# File 'lib/polyrex-feed-reader.rb', line 121 def save_css(filepath='feeds.css') lib = File.dirname(__FILE__) css_buffer = File.read(lib + '/feeds.css') #css_buffer = File.read('feeds.css') File.write filepath, css_buffer end |
#save_html(filepath = 'feeds.html') ⇒ Object
130 131 132 |
# File 'lib/polyrex-feed-reader.rb', line 130 def save_html(filepath='feeds.html') xsltproc 'feeds.xsl', @polyrex.to_xml, filepath end |
#save_latestnews(filename = 'latest.html') ⇒ 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 |
# File 'lib/polyrex-feed-reader.rb', line 134 def save_latestnews(filename='latest.html') last_modified = @polyrex.summary.last_modified e = @polyrex.xpath 'records/column/records/section/records/'\ + 'feed[summary/last_modified="' + last_modified + '"]' dynarex = Dynarex.new 'feeds/feed(source, title, link, description)' e.each() do |feed| summary = feed.element 'records/item/summary' record = { source: feed.text('summary/title'), title: summary.text('title'), link: summary.text('link'), description: summary.text('description') } dynarex.create record end #filename = 'latest.xml' =begin dynarex.save(filename) do |xml| a = xml.lines.to_a line1 = a.shift a.unshift %Q{<?xml-stylesheet title="XSL_formatting" type="text/xsl" href="latest.xsl"?>\n} a.unshift W3CENTITIES a.unshift line1 a.join end =end xsltproc 'latest.xsl', dynarex.to_xml, filename end |
#save_opml(filepath = 'feeds.opml') ⇒ Object
172 173 174 |
# File 'lib/polyrex-feed-reader.rb', line 172 def save_opml(filepath='feeds.opml') xsltproc 'opml-feeds.xsl', @polyrex.to_xml, filepath end |
#save_xml(filepath = 'feeds.xml') ⇒ Object
176 177 178 179 180 181 |
# File 'lib/polyrex-feed-reader.rb', line 176 def save_xml(filepath='feeds.xml') @polyrex.summary.last_modified = @datetimestamp @polyrex.summary.feed_count = @polyrex.xpath \ 'count(records/column/records/section/records/feed)' @polyrex.save filepath, pretty: true end |