Class: RelatonIec::IecBibliography

Inherits:
Object
  • Object
show all
Defined in:
lib/relaton_iec/iec_bibliography.rb

Overview

Class methods for search ISO standards.

Class Method Summary collapse

Class 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



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/relaton_iec/iec_bibliography.rb', line 34

def get(code, year = nil, opts = {}) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
  opts[:all_parts] ||= code.match? /\s\(all parts\)/
  ref = code.sub /\s\(all parts\)/, ""
  if year.nil?
    /^(?<code1>[^:]+):(?<year1>[^:]+)/ =~ ref
    unless code1.nil?
      ref = code1
      year = year1
    end
  end
  return iev if ref.casecmp("IEV").zero?

  ret = iecbib_get(ref, year, opts)
  return nil if ret.nil?

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

.search(text, year = nil, part = nil) ⇒ RelatonIec::HitCollection

Search for standards entries. To seach packaged document it needs to pass part parametr.

Examples:

Search for packaged standard

RelatonIec::IecBibliography.search 'IEC 60050-311', nil, '311'

Parameters:

  • text (String)
  • year (String, nil) (defaults to: nil)
  • part (String, nil) (defaults to: nil)

    search for packaged stndard if not nil

Returns:



23
24
25
26
27
# File 'lib/relaton_iec/iec_bibliography.rb', line 23

def search(text, year = nil, part = nil)
  HitCollection.new text.sub(/(^\w+)\//, '\1 '), year&.strip, part
rescue SocketError, OpenURI::HTTPError, OpenSSL::SSL::SSLError
  raise RelatonBib::RequestError, "Could not access http://www.iec.ch"
end