Module: Relaton::Iso::Bibliography

Extended by:
Bibliography
Included in:
Bibliography
Defined in:
lib/relaton/iso/bibliography.rb

Overview

Methods for search ISO standards.

Instance Method Summary collapse

Instance Method Details

#filter_hits_by_year(hit_collection, year) ⇒ Array<RelatonIso::HitCollection, Array<String>>

Returns hits and missed year IDs.

Parameters:

  • hit_collection (RelatonIso::HitCollection)
  • year (String)

Returns:

  • (Array<RelatonIso::HitCollection, Array<String>>)

    hits and missed year IDs



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/relaton/iso/bibliography.rb', line 106

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
  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

  [hit_collection, missed_year_ids]
end

#get(ref, year = nil, opts = {}) ⇒ RelatonIsoBib::IsoBibliographicItem

Returns Bibliographic item.

Parameters:

  • ref (String)

    the ISO standard Code to look up (e..g “ISO 9000”)

  • year (String, NilClass) (defaults to: nil)

    the year the standard was published

  • opts (Hash) (defaults to: {})

    options; restricted to :all_parts if all-parts

Options Hash (opts):

  • :all_parts (Boolean)

    if all-parts reference is required

  • :keep_year (Boolean)

    if undated reference should return actual reference with year

Returns:

  • (RelatonIsoBib::IsoBibliographicItem)

    Bibliographic item



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
62
63
64
65
66
67
68
69
70
71
# File 'lib/relaton/iso/bibliography.rb', line 35

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)
  query_pubid.root.all_parts ||= opts[:all_parts]
  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)

  date_filter = opts[:publication_date_before] || opts[:publication_date_after]
  if date_filter && !query_pubid.root.all_parts
    ret = find_match_by_date(hits, query_pubid, opts)
  else
    ret = hits.fetch_doc(date_filter ? opts : {})
  end
  return fetch_ref_err(query_pubid, missed_year_ids, tip_ids) unless ret

  response_pubid = ret.docidentifier.find(&:primary) # .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] ||
    opts[:publication_date_before] || opts[:publication_date_after]
  if get_all
    filter_item_by_date(ret, opts) if date_filter
    return ret
  end

  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.

Parameters:

  • query_pubid (Pubid::Iso::Identifier)

    pubid to match

  • pubid (Pubid::Iso::Identifier)

    pubid to match

  • any_types_stages (Boolean) (defaults to: false)

    match with any types and stages

Returns:

  • (<Type>)

    <description>



93
94
95
96
97
98
99
100
101
# File 'lib/relaton/iso/bibliography.rb', line 93

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

Parameters:

  • query_pubid (Pubid::Iso::Identifier)
  • pubid (Pubid::Iso::Identifier)
  • all_parts (Boolean) (defaults to: false)

    match with any parts when true

Returns:

  • (Boolean)


77
78
79
80
81
82
# File 'lib/relaton/iso/bibliography.rb', line 77

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

Parameters:

  • text (Pubid::Iso::Identifier, String)

Returns:

  • (RelatonIso::HitCollection)


18
19
20
21
22
23
24
25
# File 'lib/relaton/iso/bibliography.rb', line 18

def search(pubid, opts = {})
  pubid = ::Pubid::Iso::Identifier.parse(pubid) if pubid.is_a? String
  HitCollection.new(pubid, opts).find
rescue  SocketError, Timeout::Error, Errno::EINVAL, Errno::ECONNRESET,
        EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError,
        Net::ProtocolError, OpenSSL::SSL::SSLError, Errno::ETIMEDOUT => e
  raise Relaton::RequestError, e.message
end