Module: RelatonItu::ItuBibliography

Extended by:
ItuBibliography
Included in:
ItuBibliography
Defined in:
lib/relaton_itu/itu_bibliography.rb

Overview

Class methods for search ISO standards.

Instance Method Summary collapse

Instance Method Details

#get(code, year = nil, opts = {}) ⇒ String

Returns Relaton XML serialisation of reference.

Parameters:

  • code (String)

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

  • year (String) (defaults to: nil)

    the year the standard was published (optional)

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

    options; restricted to :all_parts if all-parts reference is required

Returns:

  • (String)

    Relaton XML serialisation of reference



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/relaton_itu/itu_bibliography.rb', line 44

def get(code, year = nil, opts = {}) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
  refid = Pubid.parse code
  refid.year ||= year
  # if year.nil?
  #   /^(?<code1>[^\s]+\s[^\s]+)\s\((?:\d{2}\/)?(?<year1>\d+)\)$/ =~ code
  #   unless code1.nil?
  #     code = code1
  #     year = year1
  #   end
  # end

  ret = itubib_get1(refid)
  return nil if ret.nil?

  ret = ret.to_most_recent_reference unless refid.year || opts[:keep_year]
  ret = ret.to_all_parts if opts[:all_parts]
  ret
end

#search(refid) ⇒ RelatonItu::HitCollection

Parameters:

Returns:



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/relaton_itu/itu_bibliography.rb', line 22

def search(refid)
  refid = RelatonItu::Pubid.parse refid if refid.is_a? String
  if refid.to_ref =~ /(ITU[\s-]T\s\w)\.(Suppl\.|Annex)\s?(\w?\d+)/
    correct_ref = "#{$~[1]} #{$~[2]} #{$~[3]}"
    Util.warn "WARNING: Incorrect reference: `#{refid}`"
    Util.warn "the reference should be: `#{correct_ref}`"
  end
  HitCollection.new refid
rescue SocketError, Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse,
       Net::HTTPHeaderSyntaxError, Net::ProtocolError, URI::InvalidURIError => e
  raise RelatonBib::RequestError, e.message
end