lib/xbel.rb in xbel-0.1.2 vs lib/xbel.rb in xbel-0.2.0

- old
+ new

@@ -1,38 +1,30 @@ require 'forwardable' require 'nokogiri' require 'nokogiri/decorators/xbel' -require 'watchr' - class XBEL < Nokogiri::XML::Document extend Forwardable def_delegators :root, :title, :title=, :desc, :desc= - autoload :Writer, 'xbel/writer' + 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 # Use <tt>XBEL.parse(string)</tt> create an instance. def initialize(*args) super decorators(Nokogiri::XML::Node) << Nokogiri::Decorators::XBEL decorate! - -# self.root = '<xbel version="1.0"></xbel>' 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.join '.' - end - - # Writes XBEL to path. - def write(path) - # TODO: should start locking write process - Writer.new(self, path).write + root.attribute('version').value = numbers * '.' end end