lib/relaton/db.rb in relaton-1.11.2 vs lib/relaton/db.rb in relaton-1.11.3

- old
+ new

@@ -61,11 +61,11 @@ # RelatonCalconnect::CcBibliographicItem, RelatinUn::UnBibliographicItem, # RelatonBipm::BipmBibliographicItem, RelatonIho::IhoBibliographicItem, # RelatonOmg::OmgBibliographicItem, RelatonW3c::W3cBibliographicItem] ## def fetch(code, year = nil, opts = {}) - stdclass = standard_class(code) || return + stdclass = @registry.class_by_ref(code) || return processor = @registry.processors[stdclass] ref = if processor.respond_to?(:urn_to_code) processor.urn_to_code(code)&.first else code end @@ -99,11 +99,11 @@ result end # Fetch asynchronously def fetch_async(code, year = nil, opts = {}, &block) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength - stdclass = standard_class code + stdclass = @registry.class_by_ref code if stdclass unless @queues[stdclass] processor = @registry.processors[stdclass] threads = ENV["RELATON_FETCH_PARALLEL"]&.to_i || processor.threads wp = WorkersPool.new(threads) do |args| @@ -140,21 +140,21 @@ def fetch_std(code, year = nil, stdclass = nil, opts = {}) std = nil @registry.processors.each do |name, processor| std = name if processor.prefix == stdclass end - std = standard_class(code) or return nil unless std + std = @registry.class_by_ref(code) or return nil unless std check_bibliocache(code, year, opts, std) end # The document identifier class corresponding to the given code # @param code [String] # @return [Array] def docid_type(code) - stdclass = standard_class(code) or return [nil, code] - _prefix, code = strip_id_wrapper(code, stdclass) + stdclass = @registry.class_by_ref(code) or return [nil, code] + _, code = strip_id_wrapper(code, stdclass) [@registry.processors[stdclass].idtype, code] end # @param key [String] # @return [Hash] @@ -216,11 +216,11 @@ # @param content [String] content in XML or YAmL format # @param edition [String, nil] edition to filter # @param year [Integer, nil] year to filter # @return [BibliographicItem, nil] def search_edition_year(file, content, edition, year) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity - processor = @registry.processors[standard_class(file.split("/")[-2])] + processor = @registry.processor_by_ref(file.split("/")[-2]) item = if file.match?(/xml$/) then processor.from_xml(content) else processor.hash_to_bib(YAML.safe_load(content)) end item if (edition.nil? || item.edition == edition) && (year.nil? || item.date.detect { |d| d.type == "published" && d.on(:year).to_s == year.to_s }) @@ -267,29 +267,17 @@ if updates doc.relation << RelatonBib::DocumentRelation.new(bibitem: updates, type: "updates") end divider = stdclass == :relaton_itu ? " " : "/" - refs[1..-1].each_with_object(doc) do |c, d| + refs[1..].each_with_object(doc) do |c, d| bib = check_bibliocache(ref + divider + c, year, opts, stdclass) if bib d.relation << RelatonBib::DocumentRelation.new( type: reltype, description: reldesc, bibitem: bib, ) end end - end - - # @param code [String] code of standard - # @return [Symbol] standard class name - def standard_class(code) - @registry.processors.each do |name, processor| - return name if /^(urn:)?#{processor.prefix}/i.match?(code) || - processor.defaultprefix.match(code) - end - Util.log <<~WARN, :info - [relaton] #{code} does not have a recognised prefix - WARN end # TODO: i18n # Fofmat ID # @param code [String]