Module: Relaton::Iho::Bibliography
- Defined in:
- lib/relaton/iho/bibliography.rb
Constant Summary collapse
- ENDPOINT =
"https://raw.githubusercontent.com/relaton/relaton-data-iho/refs/heads/v2/".freeze
Class Method Summary collapse
-
.enrich_with_pubid(item, pubid) ⇒ Object
Populate ext.structuredidentifier from the parsed Pubid when the fetched record doesn’t already provide one.
- .get(ref, year = nil, opts = {}) ⇒ RelatonIho::IhoBibliographicItem
-
.pubid_docnumber(pubid) ⇒ Object
“S-100” rather than “100” — keeps the type prefix that distinguishes the IHO series (S/P/M/B/C).
-
.search(text, _year = nil, _opts = {}) ⇒ RelatonIho::IhoBibliographicItem?
Search for IHO standard by IHO standard Code.
Class Method Details
.enrich_with_pubid(item, pubid) ⇒ Object
Populate ext.structuredidentifier from the parsed Pubid when the fetched record doesn’t already provide one. Maps ‘pubid.number` (with type prefix, e.g. `S-100`) -> docnumber, `pubid.part` -> part, `pubid.appendix` -> appendixid, `pubid.annex` -> annexid, `pubid.supplement` -> supplementid.
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/relaton/iho/bibliography.rb', line 52 def enrich_with_pubid(item, pubid) return if item.ext&.structuredidentifier&.any? sid = StructuredIdentifier.new( docnumber: pubid_docnumber(pubid), part: pubid.part, appendixid: (pubid.appendix if pubid.respond_to?(:appendix)), annexid: (pubid.annex if pubid.respond_to?(:annex)), supplementid: (pubid.supplement if pubid.respond_to?(:supplement)), ) item.ext ||= Ext.new item.ext.structuredidentifier = [sid] end |
.get(ref, year = nil, opts = {}) ⇒ RelatonIho::IhoBibliographicItem
81 82 83 |
# File 'lib/relaton/iho/bibliography.rb', line 81 def get(ref, year = nil, opts = {}) search(ref, year, opts) end |
.pubid_docnumber(pubid) ⇒ Object
“S-100” rather than “100” — keeps the type prefix that distinguishes the IHO series (S/P/M/B/C). Matches spec/fixtures/iho_part.xml.
68 69 70 |
# File 'lib/relaton/iho/bibliography.rb', line 68 def pubid_docnumber(pubid) pubid.to_s.sub(/^IHO\s/, "").split(/\s+/, 2).first end |
.search(text, _year = nil, _opts = {}) ⇒ RelatonIho::IhoBibliographicItem?
Search for IHO standard by IHO standard Code
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/relaton/iho/bibliography.rb', line 16 def search(text, _year = nil, _opts = {}) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize pubid = text.is_a?(String) ? ::Pubid::Iho::Identifier.parse(text) : text Util.info "Fetching from Relaton repository ...", key: pubid.to_s # Pass the pubid so Relaton::Index narrows candidates by number via # binary search before applying the block. Every row's `:id` is a # Pubid::Iho::Identifiers::* (Relaton::Index deserialized it via the # `pubid_class` passed in `#index`), so `pubid_match?` compares pubids. row = index.search(pubid) { |r| pubid_match?(r[:id], pubid) } .min_by { |r| r[:id].version.to_s } unless row Util.info "Not found.", key: pubid.to_s return end uri = URI("#{ENDPOINT}#{row[:file]}") resp = Net::HTTP.get_response uri unless resp.code == "200" raise Relaton::RequestError, "Could not access #{uri}: HTTP #{resp.code}" end item = Relaton::Iho::Item.from_yaml resp.body enrich_with_pubid(item, pubid) Util.info "Found: `#{item.docidentifier.first.content}`", key: pubid.to_s item.tap { |i| i.fetched = Date.today.to_s } rescue SocketError, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError, Net::ReadTimeout, OpenSSL::SSL::SSLError, Errno::ETIMEDOUT => e raise Relaton::RequestError, "Could not access #{uri}: #{e.}" end |