class Relaton::Cli::XMLConvertor
Public Class Methods
to_yaml(file, options = {})
click to toggle source
Convert to YAML
This interface allow us to convert any XML file to YAML. It only require us to provide a valid XML file and it can do converstion using default attributes, but it also allow us to provide custom options to customize this converstion process.
@param file [File] The complete path to a XML file @param options [Hash] Options as hash key, value pairs.
# File lib/relaton/cli/xml_convertor.rb, line 22 def self.to_yaml(file, options = {}) new(file, options).to_yaml end
Public Instance Methods
to_yaml()
click to toggle source
# File lib/relaton/cli/xml_convertor.rb, line 7 def to_yaml convert_and_write(file_content, :to_yaml) end
Private Instance Methods
convert_content(content)
click to toggle source
@param content [Nokogiri::XML::Document] @return [Hash]
# File lib/relaton/cli/xml_convertor.rb, line 34 def convert_content(content) if %w[bibitem bibdata].include? content.root.name Bibdata.from_xml(content) else Bibcollection.from_xml(content) end end
default_ext()
click to toggle source
# File lib/relaton/cli/xml_convertor.rb, line 28 def default_ext "yaml" end
file_content()
click to toggle source
# File lib/relaton/cli/xml_convertor.rb, line 42 def file_content Nokogiri::XML(File.read(file, encoding: "utf-8")) end