Module: XMLable::Mixins::Export

Defined in:
lib/xmlable/mixins/export.rb

Overview

Export modules contains method to export

Instance Method Summary collapse

Instance Method Details

#to_h(opts = {}) ⇒ Hash

Export to hash

Parameters:

  • opts (Hash) (defaults to: {})

Returns:

  • (Hash)


40
41
42
# File 'lib/xmlable/mixins/export.rb', line 40

def to_h(opts = {})
  Exports::JSONExporter.new(self, opts).export
end

#to_json(opts = {}) ⇒ String

Export to JSON

Parameters:

  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :pretty (Boolean)

    enable pretty print

Returns:

  • (String)

    returns exported JSON



28
29
30
31
# File 'lib/xmlable/mixins/export.rb', line 28

def to_json(opts = {})
  ret = to_h(opts)
  opts[:pretty] ? JSON.pretty_generate(ret) : ret.to_json
end

#to_xml(opts = {}) ⇒ String

Export to XML

Parameters:

  • opts (Hash) (defaults to: {})

Returns:

  • (String)

    returns exported XML



14
15
16
17
18
# File 'lib/xmlable/mixins/export.rb', line 14

def to_xml(opts = {})
  exporter = Exports::XMLExporter.new(self, opts)
  opts = self.class.__nokogiri_export_options.merge(opts)
  exporter.export.to_xml(opts).strip
end