Class: Relaton::Iec::HitCollection

Inherits:
Core::HitCollection
  • Object
show all
Defined in:
lib/relaton/iec/hit_collection.rb

Overview

Page of hit collection.

Instance Method Summary collapse

Instance Method Details

#search(exclude: [:year]) ⇒ Object

Parameters:

  • exclude (Array<Symbol>) (defaults to: [:year])

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



13
14
15
16
# File 'lib/relaton/iec/hit_collection.rb', line 13

def search(exclude: [:year])
  @array = fetch_from_index exclude
  self
end

#to_all_parts(r_year, opts = {}) ⇒ Relaton::Iec::ItemData?

Returns:



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/relaton/iec/hit_collection.rb', line 19

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[:id]&.year&.to_s == r_year) }
  if opts[:publication_date_before] || opts[:publication_date_after]
    parts = parts.select { |h| Bibliography.send(:year_in_range?, h.hit[:id].year.to_i, opts) }
  end
  hit = parts.min_by { |h| h.part.to_i }
  return @array.first&.item unless hit

  bibitem = hit.item
  all_parts_item = bibitem.to_all_parts
  parts.reject { |h| h.hit[:id] == hit.hit[:id] }.each do |hi|
    code = hi.hit[:id].to_s
    bib = ItemData.new(
      formattedref: Bib::Formattedref.new(content: code),
      docidentifier: [Docidentifier.new(content: code, type: "IEC", primary: true)],
    )
    all_parts_item.relation << Relation.new(type: "partOf", bibitem: bib)
  end
  all_parts_item
end