Module: RSMP::Convert::Import::YAML

Defined in:
lib/rsmp/convert/import/yaml.rb

Overview

Importer for SXL in YAML format.

Class Method Summary collapse

Class Method Details

.build_empty_sxlObject



27
28
29
# File 'lib/rsmp/convert/import/yaml.rb', line 27

def self.build_empty_sxl
  { meta: {}, alarms: {}, statuses: {}, commands: {} }
end

.component_definitions(yaml) ⇒ Object



31
32
33
# File 'lib/rsmp/convert/import/yaml.rb', line 31

def self.component_definitions(yaml)
  yaml.fetch('components') { yaml.fetch('objects') }
end

.convert(yaml) ⇒ Object



20
21
22
23
24
25
# File 'lib/rsmp/convert/import/yaml.rb', line 20

def self.convert(yaml)
  sxl = build_empty_sxl
  sxl[:meta] = yaml['meta']
  merge_components(sxl, component_definitions(yaml))
  sxl
end

.merge_component_items(sxl, component) ⇒ Object



41
42
43
44
45
# File 'lib/rsmp/convert/import/yaml.rb', line 41

def self.merge_component_items(sxl, component)
  component['alarms']&.each { |id, item| sxl[:alarms][id] = item }
  component['statuses']&.each { |id, item| sxl[:statuses][id] = item }
  component['commands']&.each { |id, item| sxl[:commands][id] = item }
end

.merge_components(sxl, components) ⇒ Object



35
36
37
38
39
# File 'lib/rsmp/convert/import/yaml.rb', line 35

def self.merge_components(sxl, components)
  components.each_pair do |_type, component|
    merge_component_items(sxl, component)
  end
end

.parse(str) ⇒ Object



16
17
18
# File 'lib/rsmp/convert/import/yaml.rb', line 16

def self.parse(str)
  convert ::YAML.load(str)
end

.read(path) ⇒ Object



12
13
14
# File 'lib/rsmp/convert/import/yaml.rb', line 12

def self.read(path)
  convert ::YAML.load_file(path)
end