Class: Factbase::ToXML
- Inherits:
-
Object
- Object
- Factbase::ToXML
- Defined in:
- lib/factbase/to_xml.rb
Overview
Instance Method Summary collapse
-
#initialize(fb, sorter = '_id') ⇒ ToXML
constructor
Constructor.
-
#xml ⇒ String
Convert the entire factbase into XML.
Constructor Details
permalink #initialize(fb, sorter = '_id') ⇒ ToXML
Constructor.
24 25 26 27 |
# File 'lib/factbase/to_xml.rb', line 24 def initialize(fb, sorter = '_id') @fb = fb @sorter = sorter end |
Instance Method Details
permalink #xml ⇒ String
Convert the entire factbase into XML.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/factbase/to_xml.rb', line 31 def xml bytes = @fb.export = { version: Factbase::VERSION, size: bytes.size } Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml| xml.fb() do Factbase::Flatten.new(Marshal.load(bytes), @sorter).it.each do |m| xml.f_ do m.sort.to_h.each do |k, vv| if vv.is_a?(Array) xml.send(:"#{k}_") do vv.each do |v| xml.send(:v, to_str(v), t: type_of(v)) end end else xml.send(:"#{k}_", to_str(vv), t: type_of(vv)) end end end end end end.to_xml end |