Class: PolyrexFeedReader
- Inherits:
-
Object
- Object
- PolyrexFeedReader
- Defined in:
- lib/polyrex-feed-reader.rb
Instance Method Summary collapse
- #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_xml(filepath = 'feeds.xml') ⇒ Object
Constructor Details
#initialize(polyrex) ⇒ PolyrexFeedReader
Returns a new instance of PolyrexFeedReader.
20 21 22 23 24 |
# File 'lib/polyrex-feed-reader.rb', line 20 def initialize(polyrex) @polyrex = polyrex end |
Instance Method Details
#feeds_to_html ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/polyrex-feed-reader.rb', line 26 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
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/polyrex-feed-reader.rb', line 36 def fetch_feeds() w3centities =<<EOF <!DOCTYPE stylesheet [ <!ENTITY % w3centities-f PUBLIC "-//W3C//ENTITIES Combined Set//EN//XML" "http://www.w3.org/2003/entities/2007/w3centities-f.ent"> %w3centities-f; ]> EOF 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
67 68 69 70 71 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 |
# File 'lib/polyrex-feed-reader.rb', line 67 def refresh feeds do |feed, filename| d = Dynarex.new filename feed.last_accessed = () feed.last_modified = () 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 = () end end |
#save_css(filepath = 'feeds.css') ⇒ Object
114 115 116 117 118 119 120 121 |
# File 'lib/polyrex-feed-reader.rb', line 114 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
123 124 125 |
# File 'lib/polyrex-feed-reader.rb', line 123 def save_html(filepath='feeds.html') xsltproc 'feeds.xsl', @polyrex.to_xml, filepath end |
#save_xml(filepath = 'feeds.xml') ⇒ Object
127 128 129 |
# File 'lib/polyrex-feed-reader.rb', line 127 def save_xml(filepath='feeds.xml') @polyrex.save filepath, pretty: true end |