Class: RelatonIso::HitCollection
- Inherits:
-
RelatonBib::HitCollection
- Object
- RelatonBib::HitCollection
- RelatonIso::HitCollection
- Defined in:
- lib/relaton_iso/hit_collection.rb
Overview
Page of hit collection.
Constant Summary collapse
- INDEXFILE =
"index-v1.yaml"- ENDPOINT =
"https://raw.githubusercontent.com/relaton/relaton-data-iso/main/"
Instance Method Summary collapse
- #create_pubid(id) ⇒ Object
- #create_relation(hit) ⇒ Object
- #excludings ⇒ Object
-
#fetch ⇒ Object
rubocop:disable Metrics/AbcSize.
- #fetch_doc ⇒ Object
- #index ⇒ Object
-
#initialize(pubid, opts = {}) ⇒ HitCollection
constructor
A new instance of HitCollection.
- #pubid_match?(id) ⇒ Boolean
- #ref_pubid_excluded ⇒ Object
- #ref_pubid_no_year ⇒ Object
- #to_all_parts(lang = nil) ⇒ RelatonIsoBib::IsoBibliographicItem?
Constructor Details
#initialize(pubid, opts = {}) ⇒ HitCollection
Returns a new instance of HitCollection.
13 14 15 16 |
# File 'lib/relaton_iso/hit_collection.rb', line 13 def initialize(pubid, opts = {}) super @opts = opts end |
Instance Method Details
#create_pubid(id) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/relaton_iso/hit_collection.rb', line 48 def create_pubid(id) Pubid::Iso::Identifier.create(**id) rescue StandardError => e Util.warn "(#{ref_pubid}) WARNING: #{e.}" nil end |
#create_relation(hit) ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/relaton_iso/hit_collection.rb', line 94 def create_relation(hit) docid = DocumentIdentifier.new(id: hit.pubid, type: "ISO", primary: true) isobib = RelatonIsoBib::IsoBibliographicItem.new( formattedref: RelatonBib::FormattedRef.new(content: hit.pubid.to_s), docid: [docid], ) RelatonBib::DocumentRelation.new(type: "instanceOf", bibitem: isobib) end |
#excludings ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/relaton_iso/hit_collection.rb', line 55 def excludings return @excludings if defined? @excludings excl_parts = %i[year] excl_parts << :part if ref_pubid.root.part.nil? || @opts[:all_parts] if ref_pubid.stage.nil? || @opts[:all_parts] excl_parts << :stage excl_parts << :iteration end # excl_parts << :edition if ref_pubid.root.edition.nil? || all_parts @escludings = excl_parts end |
#fetch ⇒ Object
rubocop:disable Metrics/AbcSize
29 30 31 32 33 34 35 36 |
# File 'lib/relaton_iso/hit_collection.rb', line 29 def fetch # rubocop:disable Metrics/AbcSize @array = index.search do |row| row[:id].is_a?(Hash) ? pubid_match?(row[:id]) : ref_pubid.to_s == row[:id] end.map { |row| Hit.new row, self } .sort_by! { |h| h.pubid.to_s } .reverse! self end |
#fetch_doc ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/relaton_iso/hit_collection.rb', line 72 def fetch_doc if !@opts[:all_parts] || size == 1 any? && first.fetch(@opts[:lang]) else to_all_parts(@opts[:lang]) end end |
#index ⇒ Object
68 69 70 |
# File 'lib/relaton_iso/hit_collection.rb', line 68 def index @index ||= Relaton::Index.find_or_create :iso, url: "#{ENDPOINT}index-v1.zip", file: INDEXFILE end |
#pubid_match?(id) ⇒ Boolean
38 39 40 41 42 43 44 45 46 |
# File 'lib/relaton_iso/hit_collection.rb', line 38 def pubid_match?(id) pubid = create_pubid(id) return false unless pubid pubid.base = pubid.base.exclude(:year, :edition) if pubid.base dir_excludings = excludings.dup dir_excludings << :edition unless pubid.typed_stage_abbrev == "DIR" pubid.exclude(*dir_excludings) == ref_pubid_excluded end |
#ref_pubid_excluded ⇒ Object
25 26 27 |
# File 'lib/relaton_iso/hit_collection.rb', line 25 def ref_pubid_excluded @ref_pubid_excluded ||= ref_pubid_no_year.exclude(*excludings) end |
#ref_pubid_no_year ⇒ Object
21 22 23 |
# File 'lib/relaton_iso/hit_collection.rb', line 21 def ref_pubid_no_year @ref_pubid_no_year ||= ref_pubid.dup.tap { |r| r.base = r.base.exclude(:year) if r.base } end |
#to_all_parts(lang = nil) ⇒ RelatonIsoBib::IsoBibliographicItem?
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/relaton_iso/hit_collection.rb', line 82 def to_all_parts(lang = nil) # rubocop:disable Metrics/AbcSize 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.pubid.part == hit.pubid.part }.each do |hi| all_parts_item.relation << create_relation(hi) end all_parts_item end |