Class: RelatonCen::CenBibliography

Inherits:
Object
  • Object
show all
Defined in:
lib/relaton_cen/cen_bibliography.rb

Overview

Class methods for search Cenelec standards.

Class Method Summary collapse

Class Method Details

.code_to_parts(code) ⇒ MatchData

Decopmposes a CEN standard code into its parts.

Parameters:

  • code (String)

    the CEN standard code to decompose

Returns:

  • (MatchData)

    the decomposition of the code



38
39
40
41
42
43
44
45
# File 'lib/relaton_cen/cen_bibliography.rb', line 38

def code_to_parts(code)
  %r{^
    (?<code>[^:-]+)(?:-(?<part>\d+))?
    (?::(?<year>\d{4}))?
    (?:\+(?<amd>[A-Z]\d+)(?:(?<amy>\d{4}))?)?
    (?:\/(?<ac>AC\d+:\d{4}))?
  }x.match code
end

.get(code, year = nil, opts = {}) ⇒ RelatonBib::BibliographicItem?

Parameters:

  • code (String)

    the CEN 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):

  • :keep_year (Boolean)

    don’t upate reference

Returns:

  • (RelatonBib::BibliographicItem, nil)


24
25
26
27
28
29
# File 'lib/relaton_cen/cen_bibliography.rb', line 24

def get(code, year = nil, opts = {})
  code_parts = code_to_parts code
  year ||= code_parts[:year] if code_parts

  bib_get(code, year, opts)
end

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

Parameters:

  • text (String)

Returns:



9
10
11
12
13
14
# File 'lib/relaton_cen/cen_bibliography.rb', line 9

def search(text, year = nil)
  # /^C?EN\s(?<code>.+)/ =~ text
  HitCollection.new text, year
rescue Mechanize::ResponseCodeError => e
  raise RelatonBib::RequestError, e.message
end