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 IEC standard code to look up (e..g “IEC 8000”)

  • 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



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/relaton_iec/iec_bibliography.rb', line 29

def get(code, year = nil, opts = {}) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity
  opts[:all_parts] ||= code.match?(/\s\(all parts\)/)
  ref = code.sub(/\s\(all parts\)/, "")
  year ||= ref_parts(ref)[:year]
  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(ref, year = nil) ⇒ RelatonIec::HitCollection

Search for standards entries.

Parameters:

  • ref (String)
  • year (String, nil) (defaults to: nil)

Returns:



17
18
19
20
21
22
# File 'lib/relaton_iec/iec_bibliography.rb', line 17

def search(ref, year = nil)
  # HitCollection.new text&.sub(/(^\w+)\//, '\1 '), year&.strip
  HitCollection.new ref, year&.strip
rescue SocketError, OpenURI::HTTPError, OpenSSL::SSL::SSLError => e
  raise RelatonBib::RequestError, e.message
end