Class: RelatonIso::IsoBibliography

Inherits:
Object
  • Object
show all
Defined in:
lib/relaton_iso/iso_bibliography.rb

Overview

Class methods for search ISO standards.

Class Method Summary collapse

Class Method Details

.get(ref, year = nil, opts = {}) ⇒ String

Returns Relaton XML serialisation of reference.

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 reference is required, :keep_year if undated reference should return actual reference with year

Returns:

  • (String)

    Relaton XML serialisation of reference



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/relaton_iso/iso_bibliography.rb', line 29

def get(ref, year = nil, opts = {}) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity,Metrics/AbcSize
  code = ref.gsub(/\u2013/, "-")
  # %r{\s(?<num>\d+)(?:-(?<part>[\d-]+))?(?::(?<year1>\d{4}))?} =~ code
  _, _part, year1, = ref_components ref
  year ||= year1
  code.sub! " (all parts)", ""
  opts[:all_parts] ||= $~ && opts[:all_parts].nil?
  # opts[:keep_year] ||= opts[:keep_year].nil?
  # code.sub!("#{num}-#{part}", num) if opts[:all_parts] && part
  # if %r[^ISO/IEC DIR].match? code
  #   return RelatonIec::IecBibliography.get(code, year, opts)
  # end

  ret = isobib_get1(code, year, opts)
  return nil if ret.nil?

  if year && opts[:keep_year].nil? || opts[:keep_year] || opts[:all_parts]
    ret
  else
    ret.to_most_recent_reference
  end
end

.ref_components(ref) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'lib/relaton_iso/iso_bibliography.rb', line 52

def ref_components(ref)
  %r{
    ^(?<code>ISO(?:\s|/)[^-/:()]+\d+)
    (?:-(?<part>[\w-]+))?
    (?::(?<year>\d{4}))?
    (?:/(?<corr>\w+(?:\s\w+)?\s\d+)(?:(?<coryear>\d{4}))?)?
  }x =~ ref
  [code&.strip, part, year, corr, coryear]
end

.search(text) ⇒ RelatonIso::HitCollection

Parameters:

  • text (String)

Returns:



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.message
end