lib/factbase/to_xml.rb in factbase-0.0.42 vs lib/factbase/to_xml.rb in factbase-0.0.43

- old
+ new

@@ -35,26 +35,26 @@ # Author:: Yegor Bugayenko (yegor256@gmail.com) # Copyright:: Copyright (c) 2024 Yegor Bugayenko # License:: MIT class Factbase::ToXML # Constructor. - def initialize(fb) + def initialize(fb, sorter = '_id') @fb = fb + @sorter = sorter end # Convert the entire factbase into XML. # @return [String] The factbase in XML format def xml bytes = @fb.export maps = Marshal.load(bytes) meta = { version: Factbase::VERSION, - dob: Time.now.utc.iso8601, size: bytes.size } Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml| xml.fb(meta) do - maps.each do |m| + maps.sort_by { |m| m[@sorter] }.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|