class RSScreator

Attributes

desc[RW]
description[RW]
image_target_url[RW]
image_url[RW]
limit[RW]
title[RW]
xslt[RW]

Public Class Methods

new(filepath='rss.xml', dx_xslt: nil, dx_filename: nil, custom_fields: [], limit: 10, log: nil, title: 'Untitled', description: 'Description goes here', debug: false) click to toggle source
# File lib/rss_creator.rb, line 15
def initialize(filepath='rss.xml', dx_xslt: nil, dx_filename: nil, 
               custom_fields: [], limit: 10, log: nil, title: 'Untitled', 
               description: 'Description goes here', debug: false)


  @filepath, @log, @debug = filepath, log, debug

  if dx_filename then
    
    dxfilepath = File.join(File.dirname(filepath), dx_filename)
  
    if filepath and FileX.exists? dxfilepath then

      @dx = Dynarex.new dxfilepath, debug: debug
      @title, @description, @link = @dx.title, @dx.description, @dx.link
      @image_url = @dx.image
      
    end

  else
    
    if filepath and FileX.exists? filepath
    
      rtd = RSStoDynarex.new filepath
      @dx = rtd.to_dynarex

      @title, @description, @link = @dx.title, @dx.description, @dx.link
      @image_url = @dx.image if @dx.image and @dx.image.length > 1
      @image_target_url = @link if @link and @link.length > 1
    
    else

    
      schema = 'channel[title, description, link, image]/' + \
                                'item(title, link, description, date'
      schema +=  ', ' + custom_fields.join(', ') if custom_fields.any?
      schema += ')'
      @title, @description = title, description
                                     
      @dx = Dynarex.new schema
    end

    @dx.order = 'descending'    
    @dx.default_key = 'uid'
    @dx.xslt = dx_xslt if dx_xslt    

    
  end
  
  @dx.xslt_schema = 'channel[title:title,description:description,' + \
                  'link:link]/item(title:title,description:description,' + \
                                                    'link:link,pubDate:date)'
  # maxium number of items saved in the RSS feed
  @dx.limit = @limit = limit


  @dirty = true
  @dxfilename = dx_filename

end

Public Instance Methods

add(itemx={title: '', link: '', description: ''}, item: itemx, id: nil) click to toggle source
# File lib/rss_creator.rb, line 76
def add(itemx={title: '', link: '', description: ''}, item: itemx, id: nil)

  @log.debug 'RssCreator#add item: ' + item.inspect if @log

  unless item[:title] and item[:link] then
    raise 'RSScreator: title or link can\'t be blank' 
  end
  
  record = {date: Time.now.strftime("%a, %d %b %Y %H:%M:%S %z")}.merge(item)
  @dx.create(record, id: id)
  @log&.debug 'RssCreator#add item; after @dx.create'
  
  @dirty = true
  
end
delete(id) click to toggle source
# File lib/rss_creator.rb, line 110
def delete(id)
  @dx.delete id.to_s
end
desc=(val)
Alias for: description=
description=(val) click to toggle source
# File lib/rss_creator.rb, line 105
def description=(val)
  @description = val
  @dirty = true
end
Also aliased as: desc=
dynarex() click to toggle source
# File lib/rss_creator.rb, line 117
def dynarex()
  @dx
end
image=(val)
Alias for: image_url=
image_target_url=(val) click to toggle source
# File lib/rss_creator.rb, line 128
def image_target_url=(val)
  @image_target_url = val
  @dirty = true
end
image_url=(val) click to toggle source
# File lib/rss_creator.rb, line 121
def image_url=(val)
  @image_url = val
  @dirty = true
end
Also aliased as: image=
save(new_filepath=nil) click to toggle source
# File lib/rss_creator.rb, line 92
def save(new_filepath=nil)

  filepath = new_filepath ? new_filepath : @filepath
  puts 'save() before FileX.write' if @debug
  puts 'filepath: ' + filepath.inspect if @debug
  puts 'print_rss: ' + print_rss.inspect if @debug
  FileX.write filepath, print_rss

  puts 'save() after FileX.write' if @debug

  @dx.save File.join(File.dirname(filepath), @dxfilename) if @dxfilename
end
title=(val) click to toggle source
# File lib/rss_creator.rb, line 138
def title=(val)
  @title = val
  @dirty = true
end
to_s() click to toggle source
# File lib/rss_creator.rb, line 143
def to_s()
  print_rss
end

Private Instance Methods

print_rss() click to toggle source