Class: RelatonIho::IhoBibliography

Inherits:
Object
  • Object
show all
Defined in:
lib/relaton_iho/iho_bibliography.rb

Constant Summary collapse

ENDPOINT =
"https://raw.githubusercontent.com/relaton/relaton-data-iho/"\
"master/data/".freeze

Class Method Summary collapse

Class Method Details

.get(ref, year = nil, opts = {}) ⇒ RelatonIho::IhoBibliographicItem

Parameters:

  • ref (String)

    the IHO standard Code to look up (e..g “IHO B-11”)

  • year (String) (defaults to: nil)

    the year the standard was published (optional)

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

    options

Options Hash (opts):

  • :all_parts (TrueClass, FalseClass)

    restricted to all parts if all-parts reference is required

  • :bibdata (TrueClass, FalseClass)

Returns:



38
39
40
# File 'lib/relaton_iho/iho_bibliography.rb', line 38

def get(ref, year = nil, opts = {})
  search(ref, year, opts)
end

.search(text, _year = nil, _opts = {}) ⇒ RelatonIho::IhoBibliographicItem

Parameters:

  • text (String)

Returns:



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/relaton_iho/iho_bibliography.rb', line 11

def search(text, _year = nil, _opts = {}) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
  warn "[relaton-iho] (\"#{text}\") fetching..."
  ref = text.sub(/^IHO\s/, "").downcase.sub /^([[:alpha:]]+)(\d+)/, '\1-\2'
  uri = URI("#{ENDPOINT}#{ref}.yaml")
  resp = Net::HTTP.get_response uri
  return unless resp.code == "200"

  hash = HashConverter.hash_to_bib YAML.safe_load(resp.body, [Date])
  item = IhoBibliographicItem.new hash
  warn "[relaton-iho] (\"#{text}\") found #{item.docidentifier.first.id}"
  item
rescue SocketError, Errno::EINVAL, Errno::ECONNRESET, EOFError,
       Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError,
       Net::ProtocolError, Net::ReadTimeout, # OpenSSL::SSL::SSLError,
       Errno::ETIMEDOUT => e
  raise RelatonBib::RequestError, "Could not access #{uri}: #{e.message}"
end