Module: RSMP::Convert::Import::YAML
- Defined in:
- lib/rsmp/convert/import/yaml.rb
Class Method Summary collapse
- .build_empty_sxl ⇒ Object
- .convert(yaml) ⇒ Object
- .merge_object_items(sxl, object) ⇒ Object
- .merge_objects(sxl, objects) ⇒ Object
- .parse(str) ⇒ Object
- .read(path) ⇒ Object
Class Method Details
.build_empty_sxl ⇒ Object
26 27 28 |
# File 'lib/rsmp/convert/import/yaml.rb', line 26 def self.build_empty_sxl { meta: {}, alarms: {}, statuses: {}, commands: {} } end |
.convert(yaml) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/rsmp/convert/import/yaml.rb', line 19 def self.convert(yaml) sxl = build_empty_sxl sxl[:meta] = yaml['meta'] merge_objects(sxl, yaml['objects']) sxl end |
.merge_object_items(sxl, object) ⇒ Object
36 37 38 39 40 |
# File 'lib/rsmp/convert/import/yaml.rb', line 36 def self.merge_object_items(sxl, object) object['alarms']&.each { |id, item| sxl[:alarms][id] = item } object['statuses']&.each { |id, item| sxl[:statuses][id] = item } object['commands']&.each { |id, item| sxl[:commands][id] = item } end |
.merge_objects(sxl, objects) ⇒ Object
30 31 32 33 34 |
# File 'lib/rsmp/convert/import/yaml.rb', line 30 def self.merge_objects(sxl, objects) objects.each_pair do |_type, object| merge_object_items(sxl, object) end end |
.parse(str) ⇒ Object
15 16 17 |
# File 'lib/rsmp/convert/import/yaml.rb', line 15 def self.parse(str) convert ::YAML.load(str) end |
.read(path) ⇒ Object
11 12 13 |
# File 'lib/rsmp/convert/import/yaml.rb', line 11 def self.read(path) convert ::YAML.load_file(path) end |