Class: RelatonIso::IsoBibliography
- Inherits:
-
Object
- Object
- RelatonIso::IsoBibliography
- Defined in:
- lib/relaton_iso/iso_bibliography.rb
Overview
Class methods for search ISO standards.
Class Method Summary collapse
- .filter_hits_by_year(hit_collection, year) ⇒ RelatonIso::HitCollection
-
.get(ref, year = nil, opts = {}) ⇒ RelatonIsoBib::IsoBibliographicItem
Relaton XML serialisation of reference.
- .matches_base?(query_pubid, pubid, any_types_stages: false) ⇒ Boolean
- .matches_parts?(query_pubid, pubid, all_parts: false) ⇒ Boolean
- .search(text) ⇒ RelatonIso::HitCollection
Class Method Details
.filter_hits_by_year(hit_collection, year) ⇒ RelatonIso::HitCollection
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/relaton_iso/iso_bibliography.rb', line 87 def filter_hits_by_year(hit_collection, year) missed_years = [] # filter by year hits = hit_collection.select do |hit| if hit.pubid.year == year true else missed_years << hit.pubid.year false end end if hits.empty? && !missed_years.empty? warn "[relaton-iso] (There was no match for #{year}, though there "\ "were matches found for #{missed_years.join(', ')}.)" end hits end |
.get(ref, year = nil, opts = {}) ⇒ RelatonIsoBib::IsoBibliographicItem
Returns Relaton XML serialisation of reference.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/relaton_iso/iso_bibliography.rb', line 31 def get(ref, year = nil, opts = {}) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity,Metrics/AbcSize code = ref.gsub(/\u2013/, "-") # parse "all parts" request code.sub! " (all parts)", "" opts[:all_parts] ||= $~ && opts[:all_parts].nil? query_pubid = Pubid::Iso::Identifier.parse(code) query_pubid.year = year if year hits = isobib_search_filter(query_pubid, opts) # return only first one if not all_parts ret = if !opts[:all_parts] || hits.size == 1 hits.any? && hits.first.fetch(opts[:lang]) else hits.to_all_parts(opts[:lang]) end if ret warn "[relaton-iso] (\"#{query_pubid}\") found #{ret.docidentifier.first.id}" else return fetch_ref_err(query_pubid, query_pubid.year) end if (query_pubid.year && opts[:keep_year].nil?) || opts[:keep_year] || opts[:all_parts] ret else ret.to_most_recent_reference end end |
.matches_base?(query_pubid, pubid, any_types_stages: false) ⇒ Boolean
76 77 78 79 80 81 82 |
# File 'lib/relaton_iso/iso_bibliography.rb', line 76 def matches_base?(query_pubid, pubid, any_types_stages: false) query_pubid.publisher == pubid.publisher && query_pubid.number == pubid.number && query_pubid.copublisher == pubid.copublisher && (any_types_stages && query_pubid.stage.nil? || query_pubid.stage == pubid.stage) && (any_types_stages && query_pubid.type.nil? || query_pubid.type == pubid.type) end |
.matches_parts?(query_pubid, pubid, all_parts: false) ⇒ Boolean
67 68 69 70 71 72 73 74 |
# File 'lib/relaton_iso/iso_bibliography.rb', line 67 def matches_parts?(query_pubid, pubid, all_parts: false) if all_parts # match only with documents with part number !pubid.part.nil? else query_pubid.part == pubid.part end end |
.search(text) ⇒ RelatonIso::HitCollection
14 15 16 17 18 19 20 21 |
# File 'lib/relaton_iso/iso_bibliography.rb', line 14 def search(text) HitCollection.new text.gsub(/\u2013/, "-") rescue SocketError, Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError, OpenSSL::SSL::SSLError, Errno::ETIMEDOUT, Algolia::AlgoliaUnreachableHostError => e raise RelatonBib::RequestError, e. end |