Class: RelatonBsi::BsiBibliography

Inherits:
Object
  • Object
show all
Defined in:
lib/relaton_bsi/bsi_bibliography.rb

Overview

Class methods for search ISO standards.

Class Method Summary collapse

Class Method Details

.code_parts(code) ⇒ MatchData

Destruct code to its parts.

Parameters:

  • code (String)

    document identifier

Returns:

  • (MatchData)

    parts of the code



44
45
46
47
48
49
50
51
# File 'lib/relaton_bsi/bsi_bibliography.rb', line 44

def code_parts(code)
  %r{
    ^(?:BSI\s)?(?<code>(?:[A-Z]+\s)*[^:\s+]+(?:\s\d+)?)
    (?::(?<year>\d{4}))?
    (?:\+(?<a>[^:\s]+)(?::(?<y>\d{4}))?)?
    (?:\s(?<rest>.+))?
  }x.match code
end

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

Returns Relaton XML serialisation of reference.

Parameters:

  • code (String)

    the BSI standard Code to look up

  • year (String) (defaults to: nil)

    the year the standard was published (optional)

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

    options

Options Hash (opts):

  • :all_parts (Boolean)

    if all-parts reference is required

  • :no_year (Boolean)

    if last published document is required

Returns:

  • (String)

    Relaton XML serialisation of reference



26
27
28
29
30
31
32
33
34
35
# File 'lib/relaton_bsi/bsi_bibliography.rb', line 26

def get(code, year = nil, opts = {})
  # y = code.split(":")[1]
  year ||= code_parts(code)[:year]
  ret = bib_get(code, year, opts)
  return nil if ret.nil?

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

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

Parameters:

  • text (String)

Returns:



9
10
11
12
13
14
15
16
# File 'lib/relaton_bsi/bsi_bibliography.rb', line 9

def search(text, year = nil)
  code = text.sub(/^BSI\s/, "")
  HitCollection.new code, year
rescue SocketError, Timeout::Error, Errno::EINVAL, Errno::ECONNRESET,
       EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError,
       Net::ProtocolError, Algolia::AlgoliaUnreachableHostError => e
  raise RelatonBib::RequestError, e.message
end