Module: Relaton3gpp::Bibliography

Extended by:
Bibliography
Included in:
Bibliography
Defined in:
lib/relaton_3gpp/bibliography.rb

Overview

Methods for search IANA standards.

Constant Summary collapse

SOURCE =
"https://raw.githubusercontent.com/relaton/relaton-data-3gpp/main/data/"

Instance Method Summary collapse

Instance Method Details

#get(ref, _year = nil, _opts = {}) ⇒ RelatonBib::BibliographicItem

Parameters:

  • ref (String)

    the W3C standard Code to look up

  • year (String, NilClass)

    not used

  • opts (Hash)

    options

Returns:

  • (RelatonBib::BibliographicItem)


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

def get(ref, _year = nil, _opts = {})
  warn "[relaton-3gpp] (\"#{ref}\") fetching..."
  result = search(ref)
  unless result
    warn "[relaton-3gpp] (\"#{ref}\") not found"
    return
  end

  warn "[relaton-3gpp] (\"#{ref}\") found #{result.docidentifier[0].id}"
  result
end

#search(text) ⇒ RelatonBib::BibliographicItem

Parameters:

  • text (String)

Returns:

  • (RelatonBib::BibliographicItem)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/relaton_3gpp/bibliography.rb', line 11

def search(text) # rubocop:disable Metrics/MethodLength
  file = text.sub(/^3GPP\s/, "").gsub(/[\s,:\/]/, "_").squeeze("_").upcase
  url = "#{SOURCE}#{file}.yaml"
  resp = Net::HTTP.get_response URI(url)
  return unless resp.code == "200"

  hash = YAML.safe_load resp.body
  bib_hash = Relaton3gpp::HashConverter.hash_to_bib(hash)
  Relaton3gpp::BibliographicItem.new(**bib_hash)
rescue SocketError, Timeout::Error, Errno::EINVAL, Errno::ECONNRESET,
       EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError,
       Net::ProtocolError, Errno::ETIMEDOUT => e
  raise RelatonBib::RequestError, e.message
end