Class: Factbase::ToYAML

Inherits:
Object
  • Object
show all
Defined in:
lib/factbase/to_yaml.rb

Overview

Factbase to YAML converter.

This class helps converting an entire Factbase to YAML format, for example:

require 'factbase/to_yaml'
fb = Factbase.new
puts Factbase::ToYAML.new(fb).yaml
Author

Yegor Bugayenko ([email protected])

Copyright

Copyright © 2024 Yegor Bugayenko

License

MIT

Instance Method Summary collapse

Constructor Details

#initialize(fb, sorter = '_id') ⇒ ToYAML

Constructor.



40
41
42
43
# File 'lib/factbase/to_yaml.rb', line 40

def initialize(fb, sorter = '_id')
  @fb = fb
  @sorter = sorter
end

Instance Method Details

#yamlString

Convert the entire factbase into YAML.

Returns:

  • (String)

    The factbase in YAML format



47
48
49
# File 'lib/factbase/to_yaml.rb', line 47

def yaml
  YAML.dump(Factbase::Flatten.new(Marshal.load(@fb.export), @sorter).it)
end