class Vnstat::Document
A class encapsulating document data.
@!attribute [r] data
@return [Nokogiri::XML::Document] The underlying XML document.
Attributes
data[R]
Public Class Methods
load_data(*_args)
click to toggle source
A hook used by {.open} that is intended to be overridden by subclasses.
@raise [NotImplementedError]
# File lib/vnstat/document.rb, line 29 def self.load_data(*_args) raise NotImplementedError, "Please override #{name}.#{__method__}" end
new(data)
click to toggle source
Initializes the document.
@param [String] data The raw XML data.
# File lib/vnstat/document.rb, line 15 def initialize(data) self.data = data end
open(*args)
click to toggle source
@return [Document]
# File lib/vnstat/document.rb, line 21 def self.open(*args) new(*args, load_data(*args)) end
Public Instance Methods
data=(data)
click to toggle source
Sets the raw XML data for the {Document}.
@param [String] data A string representing the document. @raise [ArgumentError] Raised if the specified data was nil.
# File lib/vnstat/document.rb, line 40 def data=(data) raise ArgumentError, 'No document data specified' if data.nil? @data = Nokogiri::XML.parse(data.to_s) end
version()
click to toggle source
Returns the version as specified in the vnstat element.
@return [String]
# File lib/vnstat/document.rb, line 50 def version attr = data.xpath('vnstat').attr('version') raise 'Unable to determine version' if attr.nil? attr.text end
xml_version()
click to toggle source
Returns the XML version as specified in the vnstat element.
@return [String]
# File lib/vnstat/document.rb, line 61 def xml_version attr = data.xpath('vnstat').attr('xmlversion') raise 'Unable to determine XML version' if attr.nil? attr.text end