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



28
29
30
31
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
58
59
60
61
62
63
64
# File 'lib/relaton_iso/iso_bibliography.rb', line 28

def get(ref, year = nil, opts = {})
  opts[:ref] = ref.gsub(/\u2013/, "-")

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

  if year.nil?
    /^(?<code1>[^\s]+(\s\w+)?\s[\d-]+)(:(?<year1>\d{4}))?(?<code2>\s\w+)?/ =~ code
    /:(?<year2>\d{4})/ =~ corr
    unless code1.nil?
      code = code1 + code2.to_s
      year = year2 || year1
    end
  end
  %r{\s(?<num>\d+)(-(?<part>[\d-]+))?} =~ code
  opts[:part] = part
  opts[:num] = num
  opts[:corr] = corr
  opts[:all_parts] ||= !part && opts[:all_parts].nil? && code2.nil?
  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] || opts[:all_parts]
    ret
  else
    ret.to_most_recent_reference
  end
end

.search(text) ⇒ RelatonIso::HitCollection



14
15
16
17
18
19
20
# 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
  raise RelatonBib::RequestError, "Could not access http://www.iso.org"
end