Class: Relaton::Iso::HitCollection
- Inherits:
-
Core::HitCollection
- Object
- Core::HitCollection
- Relaton::Iso::HitCollection
- Defined in:
- lib/relaton/iso/hit_collection.rb
Overview
Page of hit collection.
Constant Summary collapse
- ENDPOINT =
"https://raw.githubusercontent.com/relaton/relaton-data-iso/data-v2/"
Instance Method Summary collapse
- #create_pubid(id) ⇒ Object
- #create_relation(hit) ⇒ Object
- #exclude_id_attrs(pubid, *attrs) ⇒ Object
-
#excludings ⇒ Object
rubocop:disable Metrics/AbcSize.
- #fetch_doc(options = {}) ⇒ Object
-
#find ⇒ Array<Relaton::Iso::Hit>
Find all the entries that match the given reference.
- #index ⇒ Object
- #opts ⇒ Object
- #pubid_match?(id) ⇒ Boolean
- #ref_pubid_excluded ⇒ Object
- #ref_pubid_no_year ⇒ Object
- #to_all_parts ⇒ RelatonIsoBib::IsoBibliographicItem?
Instance Method Details
#create_pubid(id) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/relaton/iso/hit_collection.rb', line 51 def create_pubid(id) return id if id.is_a?(::Pubid::Core::Identifier::Base) ::Pubid::Iso::Identifier.create(**id) rescue StandardError => e Util.warn e., key: ref.to_s end |
#create_relation(hit) ⇒ Object
123 124 125 126 127 128 |
# File 'lib/relaton/iso/hit_collection.rb', line 123 def create_relation(hit) # pubid = Pubid.new hit.pubid docid = Docidentifier.new(content: hit.pubid, type: "ISO", primary: true) isobib = ItemData.new(formattedref: Bib::Formattedref.new(content: hit.pubid.to_s), docidentifier: [docid]) Relation.new(type: "instanceOf", bibitem: isobib) end |
#exclude_id_attrs(pubid, *attrs) ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/relaton/iso/hit_collection.rb', line 59 def exclude_id_attrs(pubid, *attrs) xid = pubid.exclude(*attrs) curr = xid while curr.base curr.base = curr.base.exclude(*attrs) curr = curr.base end xid end |
#excludings ⇒ Object
rubocop:disable Metrics/AbcSize
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/relaton/iso/hit_collection.rb', line 69 def excludings # rubocop:disable Metrics/AbcSize return @excludings if defined? @excludings excl_attrs = %i[year] excl_attrs << :part if ref.root.part.nil? || ref.root.all_parts if ref.stage.nil? || ref.root.all_parts excl_attrs << :stage excl_attrs << :iteration end # excl_parts << :edition if ref.root.edition.nil? || all_parts @excludings = excl_attrs end |
#fetch_doc(options = {}) ⇒ Object
95 96 97 98 99 100 101 102 103 104 |
# File 'lib/relaton/iso/hit_collection.rb', line 95 def fetch_doc( = {}) @excludings = nil if != opts @opts = if !ref.root.all_parts || size == 1 any? && first.item # (opts[:lang]) else to_all_parts end end |
#find ⇒ Array<Relaton::Iso::Hit>
Find all the entries that match the given reference.
32 33 34 35 36 37 38 39 |
# File 'lib/relaton/iso/hit_collection.rb', line 32 def find # rubocop:disable Metrics/AbcSize @array = index.search do |row| row[:id].is_a?(Hash) || row[:id].is_a?(::Pubid::Core::Identifier::Base) ? pubid_match?(row[:id]) : ref.to_s(with_prf: true) == row[:id] end.map { |row| Hit.new row, self } .sort_by! { |h| h.pubid.to_s } .reverse! self end |
#index ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/relaton/iso/hit_collection.rb', line 82 def index @index ||= Relaton::Index.find_or_create( :iso, url: "#{ENDPOINT}#{INDEXFILE}.zip", file: "#{INDEXFILE}.yaml", id_keys: %i[publisher number copublisher part year edition type stage iteration joint_document tctype sctype wgtype tcnumber scnumber wgnumber dirtype base supplements addendum jtc_dir month amendments corrigendums language], pubid_class: ::Pubid::Iso::Identifier, ) end |
#opts ⇒ Object
11 12 13 |
# File 'lib/relaton/iso/hit_collection.rb', line 11 def opts @opts ||= {} end |
#pubid_match?(id) ⇒ Boolean
41 42 43 44 45 46 47 48 49 |
# File 'lib/relaton/iso/hit_collection.rb', line 41 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" exclude_id_attrs(pubid, *dir_excludings) == ref_pubid_excluded end |
#ref_pubid_excluded ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/relaton/iso/hit_collection.rb', line 19 def ref_pubid_excluded return @ref_pubid_excluded if defined? @ref_pubid_excluded ref_excludings = excludings.dup ref_excludings << :all_parts @ref_pubid_excluded ||= ref_pubid_no_year.exclude(*ref_excludings) end |
#ref_pubid_no_year ⇒ Object
15 16 17 |
# File 'lib/relaton/iso/hit_collection.rb', line 15 def ref_pubid_no_year @ref_pubid_no_year ||= ref.base ? ref.dup.tap { |r| r.base = r.base.exclude(:year) } : ref.exclude(:year) end |
#to_all_parts ⇒ RelatonIsoBib::IsoBibliographicItem?
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/relaton/iso/hit_collection.rb', line 107 def to_all_parts # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity parts = @array.select { |h| h.pubid.part } if opts[:publication_date_before] || opts[:publication_date_after] parts = parts.select { |h| Bibliography.send(:year_in_range?, (h.pubid.year || h.hit[:year]).to_i, opts) } end hit = parts.min_by { |h| h.pubid.part.to_i } return @array.first&.item unless hit bibitem = hit.item 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 |