Sha256: e44291aa321fb60eceab69d6758d8d55c03daf108f09cc52eb160be743a47f7c

Contents?: true

Size: 852 Bytes

Versions: 3

Compression:

Stored size: 852 Bytes

Contents

module RelatonCie
  module Scrapper
    ENDPOINT = "https://raw.githubusercontent.com/relaton/relaton-data-cie/master/data/".freeze

    class << self
      # @param code [String]
      # @return [RelatonBib::BibliographicItem]
      def scrape_page(code)
        url = "#{ENDPOINT}#{code.gsub(/[\/\s\-:\.]/, '_').upcase}.yaml"
        parse_page url
      rescue OpenURI::HTTPError => e
        return if e.io.status.first == "404"

        raise RelatonBib::RequestError, "No document found for #{code} reference. #{e.message}"
      end

      private

      # @param url [String]
      # @retrurn [RelatonBib::BibliographicItem]
      def parse_page(url)
        doc = OpenURI.open_uri url
        bib_hash = RelatonBib::HashConverter.hash_to_bib YAML.safe_load(doc)
        RelatonBib::BibliographicItem.new **bib_hash
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
relaton-cie-1.8.0 lib/relaton_cie/scrapper.rb
relaton-cie-1.7.pre2 lib/relaton_cie/scrapper.rb
relaton-cie-1.7.pre1 lib/relaton_cie/scrapper.rb