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
61
62
63
|
# File 'lib/openc3/accessors/xml_accessor.rb', line 61
def self.buffer_to_doc(buffer)
Nokogiri.XML(buffer)
end
|
.doc_to_buffer(doc) ⇒ Object
65
66
67
|
# File 'lib/openc3/accessors/xml_accessor.rb', line 65
def self.doc_to_buffer(doc)
doc.to_xml
end
|
.read_item(item, buffer) ⇒ Object
24
25
26
27
28
|
# File 'lib/openc3/accessors/xml_accessor.rb', line 24
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
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/openc3/accessors/xml_accessor.rb', line 38
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
30
31
32
33
34
35
36
|
# File 'lib/openc3/accessors/xml_accessor.rb', line 30
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
51
52
53
54
55
56
57
58
59
|
# File 'lib/openc3/accessors/xml_accessor.rb', line 51
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
|