Sha256: 8e9c5f4648efb8df9766707b138f2648269e7e3372d3af8238bd4f4a3d4f12ab
Contents?: true
Size: 1.14 KB
Versions: 2
Compression:
Stored size: 1.14 KB
Contents
require 'forwardable' require 'nokogiri' require 'nokogiri/decorators/xbel' class XBEL < Nokogiri::XML::Document extend Forwardable def_delegators :root, :title, :title=, :desc, :desc= # Returns an instance of XBEL. def self.new(major = 1, minor = 0) parse %Q'<!DOCTYPE xbel PUBLIC "+//IDN python.org//DTD XML Bookmark Exchange Language 1.0//EN//XML" "http://www.python.org/topics/xml/dtds/xbel-1.0.dtd"><xbel version="%i.%i"></xbel>' % [major, minor] end # Reads file at <tt>path</tt> into <tt>parse</tt>. # @yield [XBEL] # @see Nokogiri.parse def self.open(path, &block) parse File.read(path.to_s), &block end # Calls <tt>Nokogiri#initialize</tt> and decorates XBEL nodes. def initialize(*args) super decorators(Nokogiri::XML::Node) << Nokogiri::Decorators::XBEL decorate! end # Returns node with given <tt>id</tt>. def [](id) root.at("//*[@id='#{ id }']") end # Returns an array of version numbers. def version root.attribute('version').value.split('.').map { |n| n.to_i } end # Sets version numbers. def version=(*numbers) root.attribute('version').value = numbers * '.' end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
xbel-0.2.3 | lib/xbel.rb |
xbel-0.2.2 | lib/xbel.rb |