Class: RelatonIec::HitCollection

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

Overview

Page of hit collection.

Constant Summary collapse

DOMAIN =
"https://webstore.iec.ch"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ref, year = nil, part = nil) ⇒ HitCollection

Returns a new instance of HitCollection.

Parameters:

  • ref (String)
  • year (String, nil) (defaults to: nil)
  • part (String, nil) (defaults to: nil)


18
19
20
21
22
# File 'lib/relaton_iec/hit_collection.rb', line 18

def initialize(ref, year = nil, part = nil)
  super ref, year
  @part = part
  @array = ref ? hits(ref, year) : []
end

Instance Attribute Details

#partObject (readonly)

Returns the value of attribute part.



11
12
13
# File 'lib/relaton_iec/hit_collection.rb', line 11

def part
  @part
end

Instance Method Details

#to_all_partsRelatonIec::IecBibliographicItem



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/relaton_iec/hit_collection.rb', line 25

def to_all_parts # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity
  parts = @array.reject { |h| h.part.nil? }
  hit = parts.min_by &:part
  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