Sha256: 9df841442e440184ee4e4005ed617280264afabfc541207a083b5abcf300715c
Contents?: true
Size: 1.7 KB
Versions: 1
Compression:
Stored size: 1.7 KB
Contents
# frozen_string_literal: true require "relaton_iec/hit" require "addressable/uri" module RelatonIec # Page of hit collection. class HitCollection < RelatonBib::HitCollection def_delegators :@array, :detect, :map # DOMAIN = "https://webstore.iec.ch" # @param ref [String] # @param year [String, nil] def initialize(ref, year = nil) super ref, year @index = Index.new @array = fetch_from_gh end # @return [RelatonIec::IecBibliographicItem] def to_all_parts(r_year) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity parts = @array.select { |h| h.part && h.hit[:code].match?(/^[\s\w-]+:#{r_year}/) } hit = parts.min_by { |h| h.part.to_i } return @array.first&.fetch unless hit bibitem = hit.fetch all_parts_item = bibitem.to_all_parts parts.reject { |h| h.hit[:code] == hit.hit[:code] }.each do |hi| isobib = RelatonIec::IecBibliographicItem.new( formattedref: RelatonBib::FormattedRef.new(content: hi.hit[:code]), docid: [RelatonBib::DocumentIdentifier.new(id: hi.hit[:code], type: "IEC", primary: true)], ) all_parts_item.relation << RelatonBib::DocumentRelation.new(type: "partOf", bibitem: isobib) end all_parts_item end private def fetch_from_gh return [] unless text ref = year && !/:\d{4}$/.match?(text) ? "#{text}:#{year}" : text reference = ref.sub(/^IEC\s(?=ISO\/IEC\sDIR)/, "") @index.search(reference).map do |row| # pubid = row[:pubid].is_a?(Array) ? row[:pubid][0] : row[:pubid] Hit.new({ code: row[:pubid], file: row[:file] }, self) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
relaton-iec-1.14.2 | lib/relaton_iec/hit_collection.rb |