Module: UDDF
- Defined in:
- lib/uddf.rb,
lib/uddf/version.rb,
lib/uddf/base/models.rb,
lib/uddf/v300/models.rb,
lib/uddf/v301/models.rb,
lib/uddf/v310/models.rb,
lib/uddf/v320/models.rb,
lib/uddf/v321/models.rb,
lib/uddf/v322/models.rb,
lib/uddf/v323/models.rb,
lib/uddf/v330/models.rb,
lib/uddf/v331/models.rb,
lib/uddf/base/models/deco.rb,
lib/uddf/base/models/media.rb,
lib/uddf/base/models/generic.rb,
lib/uddf/base/models/dive_computer.rb
Overview
Universal Dive Data Format (UDDF) parser and validator
Defined Under Namespace
Modules: Base, V300, V301, V310, V320, V321, V322, V323, V330, V331
Constant Summary
collapse
- SUPPORTED_SCHEMA_VERSIONS =
%w[3.0.0 3.0.1 3.1.0 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1].freeze
- SUPPORTED_PARSER_VERSIONS =
%w[3.0.0 3.0.1 3.1.0 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1].freeze
- VERSION =
"0.4.1"
Class Method Summary
collapse
Class Method Details
35
36
37
38
|
# File 'lib/uddf.rb', line 35
def self.(xml)
doc = Nokogiri::XML(xml)
doc.root&.[]("version")
end
|
.load(path, force_version: nil) ⇒ Object
15
16
17
18
|
# File 'lib/uddf.rb', line 15
def self.load(path, force_version: nil)
xml = File.read(path)
parse(xml, force_version: force_version)
end
|
.load_models_for_version(version) ⇒ Object
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/uddf.rb', line 51
def self.load_models_for_version(version)
validate_version_support(version, :parse)
module_name = "v#{version.tr(".", "")}"
require "uddf/#{module_name}/models"
const_get("#{module_name.upcase}::Models::Uddf")
end
|
.load_schema_for_version(version) ⇒ Object
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/uddf.rb', line 40
def self.load_schema_for_version(version)
@schema_cache_mutex.synchronize do
@schema_cache ||= {}
@schema_cache[version] ||= begin
validate_version_support(version, :schema)
schema_path = File.join(__dir__, "uddf", "v#{version.tr(".", "")}", "schema.xsd")
Nokogiri::XML::Schema.new(File.read(schema_path))
end
end
end
|
.parse(xml, force_version: nil) ⇒ Object
20
21
22
23
24
25
|
# File 'lib/uddf.rb', line 20
def self.parse(xml, force_version: nil)
version = force_version || (xml)
model_class = load_models_for_version(version)
model_class.parse(xml)
end
|
.validate(xml, force_version: nil) ⇒ Object
27
28
29
30
31
32
33
|
# File 'lib/uddf.rb', line 27
def self.validate(xml, force_version: nil)
version = force_version || (xml)
schema = load_schema_for_version(version)
doc = Nokogiri::XML::Document.parse(xml)
schema.validate(doc)
end
|
.validate_version_support(version, operation) ⇒ Object
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/uddf.rb', line 62
def self.validate_version_support(version, operation)
supported = case operation
when :parse then SUPPORTED_PARSER_VERSIONS
when :schema then SUPPORTED_SCHEMA_VERSIONS
end
return if supported.include?(version)
raise "Unsupported UDDF version for #{operation}, got '#{version}'"
end
|