Class: Relaton::Cli::YAMLConvertor

Inherits:
BaseConvertor show all
Defined in:
lib/relaton/cli/yaml_convertor.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseConvertor

#initialize, #to_html, to_html

Constructor Details

This class inherits a constructor from Relaton::Cli::BaseConvertor

Class Method Details

.convert_single_file(content) ⇒ RelatonBib::BibliographicItem, RelatonIso::IsoBiblioraphicItem

Parameters:

  • content (Hash)

    document in YAML format

Returns:

  • (RelatonBib::BibliographicItem, RelatonIso::IsoBiblioraphicItem)


35
36
37
38
39
40
41
42
43
# File 'lib/relaton/cli/yaml_convertor.rb', line 35

def convert_single_file(content)
  if (processor = Registry.instance.by_type(doctype(content["docid"])))
    processor.hash_to_bib content
  else
    RelatonBib::BibliographicItem.new(
      RelatonBib::HashConverter::hash_to_bib(content)
    )
  end
end

.to_xml(file, options = {}) ⇒ Object

Convert to XML

This interface allow us to convert any YAML file to XML. It only require us to provide a valid YAML file and it can do converstion using default attributes, but it also allow us to provide custom options to customize this converstion process.

Parameters:

  • file (File)

    The complete path to a YAML file

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

    Options as hash key, value pairs.



28
29
30
# File 'lib/relaton/cli/yaml_convertor.rb', line 28

def to_xml(file, options = {})
  new(file, options).to_xml
end

Instance Method Details

#to_xmlObject



8
9
10
11
12
13
14
# File 'lib/relaton/cli/yaml_convertor.rb', line 8

def to_xml
  if writable
    convert_and_write(file_content, :to_xml)
  else
    convert_content(file_content).to_xml date_format: :full, bibdata: true
  end
end