Class: OpenC3::XmlAccessor
Class Method Summary
collapse
Methods inherited from Accessor
convert_to_type, #read_item, #write_item
Class Method Details
.buffer_to_doc(buffer) ⇒ Object
58
59
60
|
# File 'lib/openc3/accessors/xml_accessor.rb', line 58
def self.buffer_to_doc(buffer)
Nokogiri.XML(buffer)
end
|
.doc_to_buffer(doc) ⇒ Object
62
63
64
|
# File 'lib/openc3/accessors/xml_accessor.rb', line 62
def self.doc_to_buffer(doc)
doc.to_xml
end
|
.read_item(item, buffer) ⇒ Object
21
22
23
24
25
|
# File 'lib/openc3/accessors/xml_accessor.rb', line 21
def self.read_item(item, buffer)
return nil if item.data_type == :DERIVED
doc = buffer_to_doc(buffer)
return convert_to_type(doc.xpath(item.key).first.to_s, item)
end
|
.read_items(items, buffer) ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/openc3/accessors/xml_accessor.rb', line 35
def self.read_items(items, buffer)
doc = buffer_to_doc(buffer)
result = {}
items.each do |item|
if item.data_type == :DERIVED
result[item.name] = nil
else
result[item.name] = convert_to_type(doc.xpath(item.key).first.to_s, item)
end
end
return result
end
|
.write_item(item, value, buffer) ⇒ Object
27
28
29
30
31
32
33
|
# File 'lib/openc3/accessors/xml_accessor.rb', line 27
def self.write_item(item, value, buffer)
return nil if item.data_type == :DERIVED
doc = buffer_to_doc(buffer)
node = doc.xpath(item.key).first
node.content = value.to_s
buffer.replace(doc_to_buffer(doc))
end
|
.write_items(items, values, buffer) ⇒ Object
48
49
50
51
52
53
54
55
56
|
# File 'lib/openc3/accessors/xml_accessor.rb', line 48
def self.write_items(items, values, buffer)
doc = buffer_to_doc(buffer)
items.each_with_index do |item, index|
next if item.data_type == :DERIVED
node = doc.xpath(item.key).first
node.content = values[index].to_s
end
buffer.replace(doc_to_buffer(doc))
end
|