Module: RelatonIso::IsoBibliography
- Extended by:
- IsoBibliography
- Included in:
- IsoBibliography
- Defined in:
- lib/relaton_iso/iso_bibliography.rb
Overview
Methods for search ISO standards.
Instance Method Summary collapse
-
#filter_hits_by_year(hit_collection, year) ⇒ Array<RelatonIso::HitCollection, Array<String>>
Hits and missed year IDs.
-
#get(ref, year = nil, opts = {}) ⇒ RelatonIsoBib::IsoBibliographicItem
Bibliographic item.
-
#matches_base?(query_pubid, pubid, any_types_stages: false) ⇒ <Type>
Matches base of query_pubid and pubid.
- #matches_parts?(query_pubid, pubid, all_parts: false) ⇒ Boolean
- #search(pubid, opts = {}) ⇒ RelatonIso::HitCollection
Instance Method Details
#filter_hits_by_year(hit_collection, year) ⇒ Array<RelatonIso::HitCollection, Array<String>>
Returns hits and missed year IDs.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/relaton_iso/iso_bibliography.rb', line 92 def filter_hits_by_year(hit_collection, year) missed_year_ids = Set.new return [hit_collection, missed_year_ids] if year.nil? # filter by year hits = hit_collection.select do |hit| hit.pubid.year ||= hit.hit[:year] next true if check_year(year, hit) missed_year_ids << hit.pubid.to_s if hit.pubid.year false end [hits, missed_year_ids] end |
#get(ref, year = nil, opts = {}) ⇒ RelatonIsoBib::IsoBibliographicItem
Returns Bibliographic item.
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 |
# File 'lib/relaton_iso/iso_bibliography.rb', line 32 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.root.year = year.to_i if year&.respond_to?(:to_i) Util.info "Fetching from Relaton repository ...", key: query_pubid.to_s hits, missed_year_ids = isobib_search_filter(query_pubid, opts) tip_ids = look_up_with_any_types_stages(hits, ref, opts) ret = hits.fetch_doc return fetch_ref_err(query_pubid, missed_year_ids, tip_ids) unless ret response_pubid = ret.docidentifier.first.id # .sub(" (all parts)", "") Util.info "Found: `#{response_pubid}`", key: query_pubid.to_s get_all = (query_pubid.root.year && opts[:keep_year].nil?) || opts[:keep_year] || opts[:all_parts] return ret if get_all ret.to_most_recent_reference rescue Pubid::Core::Errors::ParseError Util.warn "Is not recognized as a standards identifier.", key: code nil end |
#matches_base?(query_pubid, pubid, any_types_stages: false) ⇒ <Type>
Matches base of query_pubid and pubid.
79 80 81 82 83 84 85 86 87 |
# File 'lib/relaton_iso/iso_bibliography.rb', line 79 def matches_base?(query_pubid, pubid, any_types_stages: false) # rubocop:disable Metrics?PerceivedComplexity return false unless pubid.respond_to?(:publisher) query_pubid.publisher == pubid.publisher && query_pubid.number == pubid.number && query_pubid.copublisher == pubid.copublisher && (any_types_stages || query_pubid.stage == pubid.stage) && (any_types_stages || query_pubid.is_a?(pubid.class)) end |
#matches_parts?(query_pubid, pubid, all_parts: false) ⇒ Boolean
63 64 65 66 67 68 |
# File 'lib/relaton_iso/iso_bibliography.rb', line 63 def matches_parts?(query_pubid, pubid, all_parts: false) # match only with documents with part number return !pubid.part.nil? if all_parts query_pubid.part == pubid.part end |
#search(pubid, opts = {}) ⇒ RelatonIso::HitCollection
15 16 17 18 19 20 21 22 |
# File 'lib/relaton_iso/iso_bibliography.rb', line 15 def search(pubid, opts = {}) pubid = Pubid::Iso::Identifier.parse(pubid) if pubid.is_a? String HitCollection.new(pubid, opts).fetch rescue SocketError, Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError, OpenSSL::SSL::SSLError, Errno::ETIMEDOUT => e raise RelatonBib::RequestError, e. end |