Module: PROIEL::PROIELXML::Schema Private

Defined in:
lib/proiel/proiel_xml/schema.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Functionality concerned with PROIEL XML schema loading and versioning. Functionality for validation using a PROIEL XML schema is found in Validator.

Defined Under Namespace

Classes: InvalidSchemaVersion

Class Method Summary collapse

Class Method Details

.check_schema_version_of_xml_file(filename) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Opens a PROIEL XML schema file and peek at the schema version number that the file claims it conforms to.

Returns:

  • (String)

    schema version number

Raises:

  • InvalidSchemaVersion



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/proiel/proiel_xml/schema.rb', line 35

def self.check_schema_version_of_xml_file(filename)
  doc = Nokogiri::XML(File.read(filename))

  if doc and doc.root and doc.root.name == 'proiel'
    case doc.root.attr('schema-version')
    when '2.0'
      '2.0'
    when '2.1'
      '2.1'
    when '3.0'
      '3.0'
    when NilClass
      '1.0'
    else
      raise InvalidSchemaVersion, 'invalid schema version number'
    end
  else
    raise InvalidSchemaVersion, 'top-level XML element not found'
  end
end

.current_proiel_xml_schema_versionString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the current version of the PROIEL XML schema.

Returns:

  • (String)

    schema version number



18
19
20
# File 'lib/proiel/proiel_xml/schema.rb', line 18

def self.current_proiel_xml_schema_version
  '3.0'
end

.load_proiel_xml_schema(schema_version) ⇒ Nokogiri::XML::Schema

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Loads a PROIEL XML schema.

Returns:

  • (Nokogiri::XML::Schema)

    schema version number

Raises:

  • RuntimeError



62
63
64
65
66
# File 'lib/proiel/proiel_xml/schema.rb', line 62

def self.load_proiel_xml_schema(schema_version)
  filename = proiel_xml_schema_filename(schema_version)

  Nokogiri::XML::Schema(File.open(filename).read)
end

.proiel_xml_schema_filename(schema_version) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Determines the filename of a specific version of the PROIEL XML schema.

Returns:

  • (String)

    filename

Raises:

  • ArgumentError



74
75
76
77
78
79
80
81
82
# File 'lib/proiel/proiel_xml/schema.rb', line 74

def self.proiel_xml_schema_filename(schema_version)
  if schema_version == '1.0' or schema_version == '2.0' or schema_version == '2.1' or schema_version == '3.0'
    File.join(File.dirname(__FILE__),
              "proiel-#{schema_version}",
              "proiel-#{schema_version}.xsd")
  else
    raise ArgumentError, 'invalid schema version'
  end
end