class OvirtSDK4::Reader

This is the base class for all the XML readers used by the SDK. It contains the utility methods used by all of them.

@api private

Public Class Methods

parse_boolean(text) click to toggle source

Converts the given text to a boolean value.

@param text [String] @return [Boolean]

# File lib/ovirtsdk4/reader.rb, line 54
def self.parse_boolean(text)
  return nil if text.nil?
  case text.downcase
  when 'false', '0'
    return false
  when 'true', '1'
    return true
  else
    raise Error.new("The text '#{text}' isn't a valid boolean value.")
  end
end
parse_date(text) click to toggle source

Converts the given text to a date value.

@param text [String] @return [DateTime]

# File lib/ovirtsdk4/reader.rb, line 164
def self.parse_date(text)
  return nil if text.nil?
  begin
    return DateTime.xmlschema(text)
  rescue
    raise Error.new("The text '#{text}' isn't a valid date.")
  end
end
parse_decimal(text) click to toggle source

Converts the given text to a decimal value.

@return [Fixnum]

# File lib/ovirtsdk4/reader.rb, line 128
def self.parse_decimal(text)
  return nil if text.nil?
  begin
    return Float(text)
  rescue
    raise Error.new("The text '#{text}' isn't a valid decimal value.")
  end
end
parse_integer(text) click to toggle source

Converts the given text to an integer value.

@param text [String] @return [Integer]

# File lib/ovirtsdk4/reader.rb, line 93
def self.parse_integer(text)
  return nil if text.nil?
  begin
    return Integer(text, 10)
  rescue
    raise Error.new("The text '#{text}' isn't a valid integer value.")
  end
end
read_boolean(reader) click to toggle source

Reads a boolean value, assuming that the cursor is positioned at the start element that contains the value.

@param reader [XmlReader] @return [Boolean]

# File lib/ovirtsdk4/reader.rb, line 72
def self.read_boolean(reader)
  return Reader.parse_boolean(reader.read_element)
end
read_booleans(reader) click to toggle source

Reads a list of boolean values, assuming that the cursor is positioned at the start element that contains the values.

@param reader [XmlReader] @return [Array<Boolean>]

# File lib/ovirtsdk4/reader.rb, line 83
def self.read_booleans(reader)
  return reader.read_elements.map { |text| Reader.parse_boolean(text) }
end
read_date(reader) click to toggle source

Reads a date value, assuming that the cursor is positioned at the start element that contains the value.

@param reader [XmlReader] @return [DateTime]

# File lib/ovirtsdk4/reader.rb, line 179
def self.read_date(reader)
  return Reader.parse_date(reader.read_element)
end
read_dates(reader) click to toggle source

Reads a list of dates values, assuming that the cursor is positioned at the start element that contains the values.

@param reader [XmlReader] @return [Array<DateTime>]

# File lib/ovirtsdk4/reader.rb, line 190
def self.read_dates(reader)
  return reader.read_elements.map { |text| Reader.parse_date(text) }
end
read_decimal(reader) click to toggle source

Reads a decimal value, assuming that the cursor is positioned at the start element that contains the value.

@param reader [XmlReader] @return [Fixnum]

# File lib/ovirtsdk4/reader.rb, line 143
def self.read_decimal(reader)
  return Reader.parse_decimal(reader.read_element)
end
read_decimals(reader) click to toggle source

Reads a list of decimal values, assuming that the cursor is positioned at the start element that contains the values.

@param reader [XmlReader] @return [Array<Fixnum>]

# File lib/ovirtsdk4/reader.rb, line 154
def self.read_decimals(reader)
  return reader.read_elements.map { |text| Reader.parse_decimal(text) }
end
read_integer(reader) click to toggle source

Reads an integer value, assuming that the cursor is positioned at the start element that contains the value.

@param reader [XmlReader] @return [Integer]

# File lib/ovirtsdk4/reader.rb, line 108
def self.read_integer(reader)
  return Reader.parse_integer(reader.read_element)
end
read_integers(reader) click to toggle source

Reads a list of integer values, assuming that the cursor is positioned at the start element that contains the values.

@param reader [XmlReader] @return [Array<Integer>]

# File lib/ovirtsdk4/reader.rb, line 119
def self.read_integers(reader)
  return reader.read_elements.map { |text| Reader.parse_integer(text) }
end
read_string(reader) click to toggle source

Reads a string value, assuming that the cursor is positioned at the start element that contains the value.

@param reader [XmlReader] @return [String]

# File lib/ovirtsdk4/reader.rb, line 33
def self.read_string(reader)
  return reader.read_element
end
read_strings(reader) click to toggle source

Reads a list of string values, assuming that the cursor is positioned at the start of the element that contains the first value.

@param reader [XmlReader] @return [Array<String>]

# File lib/ovirtsdk4/reader.rb, line 44
def self.read_strings(reader)
  return reader.read_elements
end