Class: RelatonBsi::BsiBibliography
- Inherits:
-
Object
- Object
- RelatonBsi::BsiBibliography
- Defined in:
- lib/relaton_bsi/bsi_bibliography.rb
Overview
Class methods for search ISO standards.
Class Method Summary collapse
-
.code_parts(code) ⇒ MatchData
Destruct code to its parts.
-
.get(code, year = nil, opts = {}) ⇒ String
Relaton XML serialisation of reference.
- .search(text, year = nil) ⇒ RelatonBsi::HitCollection
Class Method Details
.code_parts(code) ⇒ MatchData
Destruct code to its parts.
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.
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
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. end |