Sha256: 46182d5bd487ce3efa7d5f170f7705d668320129bf10d4a2d6a5fdecdc2c2f1d

Contents?: true

Size: 1.16 KB

Versions: 18

Compression:

Stored size: 1.16 KB

Contents

require "thor"
require "relaton"
require "relaton/xml_document"
require_relative "cli/command"

module Relaton
  module Cli
    def self.start(arguments)
      Relaton::Cli::Command.start(arguments)
    end

    # Relaton
    #
    # Based on current setup, we need to initiate a Db instance to
    # register all of it's supported processor backends. To make it
    # easier we have added it as a class method so we can use this
    # whenever necessary.
    #
    def self.relaton
      @relaton ||= Relaton::Db.new("#{Dir.home}/.relaton/cache", nil)
    end

    # @param content [Nokogiri::XML::Document]
    # @return [RelatonBib::BibliographicItem, RelatonIsoBib::IsoBibliongraphicItem]
    def self.parse_xml(doc)
      if (processor = Relaton::Registry.instance.by_type(Relaton::Cli.doctype(doc)))
        processor.from_xml(doc.to_s)
      else
        RelatonBib::XMLParser.from_xml(doc.to_s)
      end
    end

    # @param content [Nokogiri::XML::Document] Document
    # @return [String] Type prefix
    def self.doctype(doc)
      docid = doc.at "docidentifier"
      return docid[:type] if docid && docid[:type]

      docid&.text&.match(/^\w+/)&.to_s
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
relaton-cli-0.5.0 lib/relaton/cli.rb
relaton-cli-0.4.3 lib/relaton/cli.rb
relaton-cli-0.4.2 lib/relaton/cli.rb
relaton-cli-0.4.1 lib/relaton/cli.rb
relaton-cli-0.4.0 lib/relaton/cli.rb
relaton-cli-0.3.19 lib/relaton/cli.rb
relaton-cli-0.3.18 lib/relaton/cli.rb
relaton-cli-0.3.17 lib/relaton/cli.rb
relaton-cli-0.3.16 lib/relaton/cli.rb
relaton-cli-0.3.15 lib/relaton/cli.rb
relaton-cli-0.3.14 lib/relaton/cli.rb
relaton-cli-0.3.13 lib/relaton/cli.rb
relaton-cli-0.3.12 lib/relaton/cli.rb
relaton-cli-0.3.11 lib/relaton/cli.rb
relaton-cli-0.3.10 lib/relaton/cli.rb
relaton-cli-0.3.9 lib/relaton/cli.rb
relaton-cli-0.3.8 lib/relaton/cli.rb
relaton-cli-0.3.7 lib/relaton/cli.rb