Class: RSMP::SXL::Processing::Document
- Inherits:
-
Object
- Object
- RSMP::SXL::Processing::Document
- Defined in:
- lib/rsmp/sxl/processing/document.rb
Overview
A validated SXL YAML document with a normalized component structure.
Defined Under Namespace
Classes: SymbolDefinition
Constant Summary collapse
- NAME =
%r{\A[a-z0-9][a-z0-9_/-]*\z}- PREFIX =
%r{\A[a-zA-Z0-9_/-]+/\z}- MESSAGE_KINDS =
%w[alarms statuses commands].freeze
Instance Attribute Summary collapse
-
#component_types ⇒ Object
readonly
Returns the value of attribute component_types.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#dependencies ⇒ Object
readonly
Returns the value of attribute dependencies.
-
#message_codes ⇒ Object
readonly
Returns the value of attribute message_codes.
-
#minimum_core_version ⇒ Object
readonly
Returns the value of attribute minimum_core_version.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
-
#version_string ⇒ Object
readonly
Returns the value of attribute version_string.
Class Method Summary collapse
- .load(path) ⇒ Object
- .parse(source, path: '(SXL source)') ⇒ Object
- .validate_name!(value, label: 'SXL name') ⇒ Object
Instance Method Summary collapse
-
#initialize(path:, data:) ⇒ Document
constructor
A new instance of Document.
Constructor Details
#initialize(path:, data:) ⇒ Document
40 41 42 43 44 45 46 47 48 |
# File 'lib/rsmp/sxl/processing/document.rb', line 40 def initialize(path:, data:) @path = path @data = normalize_document(require_hash(data, 'document')) read_dependencies read_symbols rescue Error => e raise Error, "#{path}: #{e.message}" end |
Instance Attribute Details
#component_types ⇒ Object (readonly)
Returns the value of attribute component_types.
14 15 16 |
# File 'lib/rsmp/sxl/processing/document.rb', line 14 def component_types @component_types end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
14 15 16 |
# File 'lib/rsmp/sxl/processing/document.rb', line 14 def data @data end |
#dependencies ⇒ Object (readonly)
Returns the value of attribute dependencies.
14 15 16 |
# File 'lib/rsmp/sxl/processing/document.rb', line 14 def dependencies @dependencies end |
#message_codes ⇒ Object (readonly)
Returns the value of attribute message_codes.
14 15 16 |
# File 'lib/rsmp/sxl/processing/document.rb', line 14 def end |
#minimum_core_version ⇒ Object (readonly)
Returns the value of attribute minimum_core_version.
14 15 16 |
# File 'lib/rsmp/sxl/processing/document.rb', line 14 def minimum_core_version @minimum_core_version end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
14 15 16 |
# File 'lib/rsmp/sxl/processing/document.rb', line 14 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
14 15 16 |
# File 'lib/rsmp/sxl/processing/document.rb', line 14 def path @path end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
14 15 16 |
# File 'lib/rsmp/sxl/processing/document.rb', line 14 def version @version end |
#version_string ⇒ Object (readonly)
Returns the value of attribute version_string.
14 15 16 |
# File 'lib/rsmp/sxl/processing/document.rb', line 14 def version_string @version_string end |
Class Method Details
.load(path) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/rsmp/sxl/processing/document.rb', line 17 def self.load(path) = File.(path) raise Error, "SXL source #{path} not found" unless File.exist?() raise Error, "SXL source #{path} is not a file" unless File.file?() parse(File.read(, encoding: 'UTF-8'), path: ) rescue EncodingError => e raise Error, "Cannot read SXL source #{path}: #{e.message}" end |
.parse(source, path: '(SXL source)') ⇒ Object
27 28 29 30 31 32 |
# File 'lib/rsmp/sxl/processing/document.rb', line 27 def self.parse(source, path: '(SXL source)') data = Psych.safe_load(source, permitted_classes: [], permitted_symbols: [], aliases: false) new(path: path, data: data) rescue Psych::Exception => e raise Error, "Cannot read SXL source #{path}: #{e.message}" end |
.validate_name!(value, label: 'SXL name') ⇒ Object
34 35 36 37 38 |
# File 'lib/rsmp/sxl/processing/document.rb', line 34 def self.validate_name!(value, label: 'SXL name') return value if value.is_a?(String) && NAME.match?(value) raise Error, "Invalid #{label} #{value.inspect}" end |