module OPML

Constants

MAJOR
MINOR
PATCH
VERSION

Public Class Methods

banner() click to toggle source
load( xml ) click to toggle source
# File lib/opmlparser.rb, line 14
def self.load( xml )
  parse( xml, outlinify: false )
end
load_file( path ) click to toggle source
# File lib/opmlparser.rb, line 18
def self.load_file( path )
  xml = File.open( path, 'r:utf-8' ) { |f| f.read }
  load( xml )
end
parse( xml, outlinify: false ) click to toggle source
helper methods

(internal) helper method

# File lib/opmlparser.rb, line 27
def self.parse( xml, outlinify: false )
  opml = REXML::Document.new( xml )

  ### parse head
  meta    = {}
  opml.elements['opml/head'].elements.each do |el|
    meta[ el.name ] = el.text
  end

  ## parse body
  outline = []
  parse_outline( outline, opml.elements['opml/body'], outlinify: outlinify )

  if outlinify
    Outline.new( { 'meta'    => Outline::Meta.new( meta ),
                   'outline' => outline } )
  else
    { 'meta'    => meta,
      'outline' => outline }
  end
end
parse_outline( outlines, node, outlinify:) click to toggle source
# File lib/opmlparser.rb, line 49
def self.parse_outline( outlines, node, outlinify:)
  node.elements.each( 'outline' ) do |el|
    outline    = {}

    el.attributes.each do |attr|
      outline[ attr[0] ] =  attr[1]
    end

    if el.elements.size > 0
      children = []
      parse_outline( children, el, outlinify: outlinify )
      outline[ 'outline' ] = children
    end

    ## todo/fix: find a better name - use easyaccess or something?
    ##  outlinify - wrap hash for easy access in Outline class
    outlines <<   if outlinify   ## wrap in Outline
                    Outline.new( outline )
                  else
                    outline
                  end
  end
end
root() click to toggle source
# File lib/opmlparser/version.rb, line 16
def self.root
  "#{File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )}"
end
version() click to toggle source
# File lib/opmlparser/version.rb, line 8
def self.version
  VERSION
end