Class: MyMediaDynarex
- Inherits:
-
MyMedia::Base
- Object
- MyMedia::Base
- MyMediaDynarex
- Defined in:
- lib/mymedia-dynarex.rb
Instance Method Summary collapse
- #copy_edit(src_path, destination, raw = '') ⇒ Object
- #copy_publish(filename, raw_msg = '') ⇒ Object
-
#initialize(media_type: 'mmdynarex', public_type: 'dynarex', config: nil) ⇒ MyMediaDynarex
constructor
A new instance of MyMediaDynarex.
Constructor Details
#initialize(media_type: 'mmdynarex', public_type: 'dynarex', config: nil) ⇒ MyMediaDynarex
Returns a new instance of MyMediaDynarex.
14 15 16 17 18 19 20 21 22 |
# File 'lib/mymedia-dynarex.rb', line 14 def initialize(media_type: 'mmdynarex', public_type: 'dynarex', config: nil) @xsl = '/xsl/dynarex-c.xsl' super(media_type: media_type, public_type: @public_type=public_type, config: config) @media_src = "%s/media/%s" % [@home, public_type] @target_ext = '.xml' @rss = true end |
Instance Method Details
#copy_edit(src_path, destination, raw = '') ⇒ Object
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 118 |
# File 'lib/mymedia-dynarex.rb', line 80 def copy_edit(src_path, destination, raw='') txt_destination = destination.sub(/xml$/,'txt') FileUtils.cp src_path, txt_destination dynarex = Dynarex.new buffer = File.read(src_path) dynarex.parse(File.read(src_path)) title = dynarex.summary[:title] = if dynarex.summary.include? :tags then '#' + dynarex..split.join(' #') else '' end raw_msg = ("%s %s" % [title, ]).strip if dynarex.type == 'feed' then h = dynarex.to_h.first if h[:tags] then = h[:tags].gsub(/\b\w/,'#\0') s = h.first.last raw_msg = ((s + ).length > 130 ? s[0..127] + '...' : s) \ + ' ' + end end dynarex.summary[:original_source] = File.basename(src_path) dynarex.summary[:source] = File.basename(txt_destination) dynarex.xslt = @xsl unless dynarex.xslt dynarex.save(destination) [dynarex, raw_msg] end |
#copy_publish(filename, raw_msg = '') ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 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 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/mymedia-dynarex.rb', line 24 def copy_publish(filename, raw_msg='') src_path = File.join(@media_src, filename) unless File.exists? src_path then raise MyMediaDynarexException, "file not found : " + src_path end file_publish(src_path, raw_msg) do |destination, raw_destination| if not raw_msg or raw_msg.empty? then raw_msg = File.basename(src_path) + " updated: " + Time.now.to_s end if File.extname(src_path) == '.txt' then dynarex, raw_msg = copy_edit(src_path, destination) copy_edit(src_path, raw_destination) else dynarex = Dynarex.new(src_path) title = dynarex.summary['title'] || '' dynarex.summary[:original_source] = File.basename(src_path) dynarex.xslt = '/xsl/dynarex-c.xsl' unless dynarex.xslt dynarex.save(destination) end if not File.basename(src_path)[/d\d{6}T\d{4}\.txt/] then xml_filename = File.basename(src_path).sub(/txt$/,'xml') FileUtils.cp destination, @home + '/dynarex/' + xml_filename if File.extname(src_path) == '.txt' then FileUtils.cp src_path, @home + '/dynarex/' + File.basename(src_path) end dynarex_filepath = @home + '/dynarex/static.xml' if dynarex.type == 'feed' then @static_baseurl = "%s/%s/%s/" % [@website, @public_type, \ File.basename(src_path)[/.*(?=\.\w+$)/]] target_url = @static_baseurl + dynarex.records.first.last[:id] else target_url = "%s/dynarex/%s" % [@website, xml_filename] end publish_dynarex(dynarex_filepath, {title: xml_filename, url: target_url }) end [raw_msg,target_url] end end |