Class: Lutaml::Store::Format::Xml

Inherits:
Base
  • Object
show all
Defined in:
lib/lutaml/store/format/xml.rb

Instance Method Summary collapse

Methods inherited from Base

#binary?

Instance Method Details

#deserialize(data, model_class) ⇒ Object



19
20
21
# File 'lib/lutaml/store/format/xml.rb', line 19

def deserialize(data, model_class)
  model_class.from_xml(data)
end

#deserialize_many(data, model_class) ⇒ Object



28
29
30
31
32
33
# File 'lib/lutaml/store/format/xml.rb', line 28

def deserialize_many(data, model_class)
  doc = Moxml.parse(data)
  doc.root.children.select(&:element?).map do |child|
    model_class.from_xml(child.to_xml)
  end
end

#extensionObject



7
8
9
# File 'lib/lutaml/store/format/xml.rb', line 7

def extension
  ".xml"
end

#glob_patternObject



11
12
13
# File 'lib/lutaml/store/format/xml.rb', line 11

def glob_pattern
  "*.xml"
end

#serialize(model) ⇒ Object



15
16
17
# File 'lib/lutaml/store/format/xml.rb', line 15

def serialize(model)
  model.to_xml
end

#serialize_many(models) ⇒ Object



23
24
25
26
# File 'lib/lutaml/store/format/xml.rb', line 23

def serialize_many(models)
  inner = models.map(&:to_xml).join("\n")
  "<items>\n#{inner}\n</items>"
end