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(code, year, opts) ⇒ String

Returns Relaton XML serialisation of reference.

Parameters:

  • code (String)

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

  • year (String)

    the year the standard was published (optional)

  • opts (Hash)

    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



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 33

def get(code, year, opts)
  %r{
    ^(?<code1>[^\s]+\s[^/]+) # match code
    /?
    (?<corr>(Amd|DAmd|(CD|WD|AWI|NP)\sAmd|Cor|CD\sCor|FDAmd)\s\d+ # correction name
    :?(\d{4})?(/Cor\s\d+:\d{4})?) # match correction year
  }x =~ code
  code = code1 if code1

  if year.nil?
    /^(?<code1>[^\s]+(\s\w+)?\s[\d-]+)(:(?<year1>\d{4}))?(?<code2>\s\w+)?/ =~ code
    unless code1.nil?
      code = code1 + code2.to_s
      year = year1
    end
  end
  opts[:all_parts] ||= code !~ %r{^[^\s]+\s\d+-\d+} && opts[:all_parts].nil? && code2.nil?
  return RelatonIec::IecBibliography.get(code, year, opts) if %r[^ISO/IEC DIR] =~ code

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

  ret.to_most_recent_reference unless year || opts[:keep_year] || opts[:all_parts]
  ret
end

.search(text) ⇒ RelatonIso::HitPages

Parameters:

  • text (String)

Returns:

  • (RelatonIso::HitPages)


14
15
16
17
18
19
20
# File 'lib/relaton_iso/iso_bibliography.rb', line 14

def search(text)
  HitCollection.new text
rescue SocketError, Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError,
       Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError,
       OpenSSL::SSL::SSLError, Errno::ETIMEDOUT
  raise RelatonBib::RequestError, "Could not access http://www.iso.org"
end