Class: RelatonIec::HitCollection

Inherits:
RelatonBib::HitCollection
  • Object
show all
Defined in:
lib/relaton_iec/hit_collection.rb

Overview

Page of hit collection.

Instance Method Summary collapse

Constructor Details

#initialize(pubid, exclude: [:year]) ⇒ HitCollection

Returns a new instance of HitCollection.

Parameters:

  • pubid (Pubid::Iec::Identifier)
  • exclude (Array<Symbol>) (defaults to: [:year])

    keys to exclude from comparison (e.g. :year, :part, :type)



13
14
15
16
17
18
19
20
21
22
# File 'lib/relaton_iec/hit_collection.rb', line 13

def initialize(pubid, exclude: [:year])
  super pubid.to_s
  @pubid = pubid
  @exclude = exclude
  @index = Relaton::Index.find_or_create(
    :iec, url: "#{Hit::GHURL}#{INDEXFILE}.zip", file: "#{INDEXFILE}",
    pubid_class: Pubid::Iec::Identifier
  )
  @array = fetch_from_index
end

Instance Method Details

#to_all_parts(r_year, opts = {}) ⇒ RelatonIec::IecBibliographicItem

Parameters:

  • r_year (String, nil)
  • opts (Hash) (defaults to: {})

Returns:



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/relaton_iec/hit_collection.rb', line 27

def to_all_parts(r_year, opts = {}) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
  parts = @array.select { |h| h.part && (!r_year || h.hit[:pubid].year&.to_s == r_year) }
  if opts[:publication_date_before] || opts[:publication_date_after]
    parts = parts.select { |h| IecBibliography.send(:year_in_range?, h.hit[:pubid].year.to_i, opts) }
  end
  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[:pubid] == hit.hit[:pubid] }.each do |hi|
    code = hi.hit[:pubid].to_s
    isobib = RelatonIec::IecBibliographicItem.new(
      formattedref: RelatonBib::FormattedRef.new(content: code),
      docid: [DocumentIdentifier.new(id: hi.hit[:pubid], type: "IEC", primary: true)],
    )
    all_parts_item.relation << RelatonBib::DocumentRelation.new(type: "partOf", bibitem: isobib)
  end
  all_parts_item
end