Class: MyMedia::Base

Inherits:
Publisher show all
Includes:
RXFileIOModule, StringFilter
Defined in:
lib/mymedia.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from StringFilter

#normalize

Constructor Details

#initialize(media_type: 'blog', public_type: media_type, ext: 'txt', config: nil, log: nil, now: Time.now, debug: false) ⇒ Base

Returns a new instance of Base.

Raises:



217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# File 'lib/mymedia.rb', line 217

def initialize(media_type: 'blog', public_type: media_type,
               ext: 'txt', config: nil, log: nil, now: Time.now,
               debug: false)

  super()      

  @now = now
  @schema = 'posts/post(title, url, raw_url)'      

  raise BaseException, "no config found" unless config

  c = SimpleConfig.new(config).to_h
  
  @home = c[:home]
  puts '@home: ' + @home.inspect if @debug
  @media_src = "%s/media/%s" % [@home, media_type]
  @website = c[:website]    

  @dynamic_website = c[:dynamic_website]
  @www = c[:www]
  @domain = @website[/[^\.]+\.[^\.]+$/]

  @sps = c[:sps]
  @omit_html_ext = c[:omit_html_ext]
  
  @log = log


  @media_type = media_type
  @public_type = public_type ||= @media_type
  
  @xslt_schema = 'channel[title:title,description:desc]/' + \
                                            'item(title:title,link:url)'
  @ext = ext
  @rss = false
  @debug = debug
  
  DirX.chdir @home

end

Instance Attribute Details

#destinationObject (readonly)

Returns the value of attribute destination.



215
216
217
# File 'lib/mymedia.rb', line 215

def destination
  @destination
end

#to_sObject (readonly)

Returns the value of attribute to_s.



215
216
217
# File 'lib/mymedia.rb', line 215

def to_s
  @to_s
end

Instance Method Details

#add_feed_item(raw_msg, record, options = {}) ⇒ Object



258
259
260
261
262
263
264
265
266
267
268
# File 'lib/mymedia.rb', line 258

def add_feed_item(raw_msg, record, options={})
  
  dynarex_filepath = File.join([@home, @www, @public_type, 'dynarex.xml'])        
  id = Increment.update(File.join([@home, @www, @public_type, 'counter.txt'])) 
  static_url = @static_baseurl + id
  record[:uri] = static_url
  
  publish_dynarex(dynarex_filepath, record, {id: id}.merge(options))                    
  publish_timeline(raw_msg, static_url)         
  publish_html(@home + '/index.html') 
end

#auto_copy_publish(raw_msg = '', &blk) ⇒ Object



270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
# File 'lib/mymedia.rb', line 270

def auto_copy_publish(raw_msg='', &blk)

  @log.info 'Base inside auto_copy_publish' if @log
  puts '@media_src: ' + @media_src.inspect if @debug

  # fetch the most recent file
  filename = FileX.ru_r @media_src

  if filename then

    puts 'filename: ' + filename.inspect if @debug

    copy_publish( filename ,raw_msg, &blk)

  end

end

#basename(raw_s1, raw_s2) ⇒ Object



288
289
290
291
292
293
294
295
# File 'lib/mymedia.rb', line 288

def basename(raw_s1, raw_s2)

  s1 = raw_s1.sub(/dfs:\/\/[^\/]+/,'')
  s2 = raw_s2.sub(/dfs:\/\/[^\/]+/,'')

  (s2.split('/') - s1.split('/')).join('/')

end

#copy_publish(filename, raw_msg = '', &blk) ⇒ Object



297
298
299
# File 'lib/mymedia.rb', line 297

def copy_publish(filename, raw_msg='', &blk)
  file_publish(filename, raw_msg)
end