Class: RelatonIso::HitCollection

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

Overview

Page of hit collection.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ HitCollection

Returns a new instance of HitCollection.

Parameters:

  • text (String)

    reference to search



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

def initialize(text)
  super
  @from_gh = text.match?(/^ISO[\s\/](?:TC\s184\/SC\s?4|IEC\sDIR\s(?:\d|IEC|JTC))/)
end

Instance Attribute Details

#from_ghBoolean (readonly)

Returns whether the search was performed on GitHub.

Returns:

  • (Boolean)

    whether the search was performed on GitHub



10
11
12
# File 'lib/relaton_iso/hit_collection.rb', line 10

def from_gh
  @from_gh
end

Instance Method Details

#fetchObject



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

def fetch
  @array = from_gh ? fetch_github : fetch_iso
  self
end

#to_all_parts(lang = nil) ⇒ RelatonIsoBib::IsoBibliographicItem?

Parameters:

  • lang (String, NilClass) (defaults to: nil)

Returns:

  • (RelatonIsoBib::IsoBibliographicItem, nil)


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

def to_all_parts(lang = nil) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
  # parts = @array.reject { |h| h.hit["docPart"]&.empty? }
  hit = @array.min_by { |h| h.pubid.part.to_i }
  return @array.first&.fetch lang unless hit

  bibitem = hit.fetch(lang)
  all_parts_item = bibitem.to_all_parts
  @array.reject { |h| h.hit[:uuid] == hit.hit[:uuid] }.each do |hi|
    isobib = RelatonIsoBib::IsoBibliographicItem.new(
      formattedref: RelatonBib::FormattedRef.new(content: hi.pubid.to_s),
    )
    all_parts_item.relation << RelatonBib::DocumentRelation.new(
      type: "instanceOf", bibitem: isobib,
    )
  end
  all_parts_item
end