class Geoblacklight::Metadata::Base

Abstract Class for metadata

Attributes

reference[R]

Public Class Methods

new(reference) click to toggle source

Instantiates a Geoblacklight::Metadata object used for retrieving and formatting metadata @param reference [Geoblacklight::Reference] the reference object

# File lib/geoblacklight/metadata/base.rb, line 17
def initialize(reference)
  @reference = reference
end

Public Instance Methods

blank?() click to toggle source

Determines whether or not a metadata resources is empty @return [Boolean]

# File lib/geoblacklight/metadata/base.rb, line 31
def blank?
  document.nil? || document.children.empty?
end
document() click to toggle source

Retrieves the XML Document for the metadata @return [Nokogiri::XML::Document]

# File lib/geoblacklight/metadata/base.rb, line 24
def document
  @document ||= metadata.metadata
end
endpoint() click to toggle source

Retrieves the URI for the reference resource (e. g. a service endpoint) @return [String, nil]

# File lib/geoblacklight/metadata/base.rb, line 38
def endpoint
  blank? ? nil : @reference.endpoint
end

Private Instance Methods

metadata() click to toggle source

Handles metadata and returns the retrieved metadata or an error message if something went wrong @return [String] returned metadata string

# File lib/geoblacklight/metadata/base.rb, line 75
def metadata
  response_body = retrieve_metadata
  metadata_class.new(response_body)
end
metadata_class() click to toggle source

Retrieve the Class for the GeoCombine data model @return [GeoCombine::Metadata]

# File lib/geoblacklight/metadata/base.rb, line 67
def metadata_class
  GeoCombine::Metadata
end
retrieve_metadata() click to toggle source

Retrieves metadata from a url source @return [String, nil] metadata string or nil if there is a connection error

# File lib/geoblacklight/metadata/base.rb, line 48
def retrieve_metadata
  connection = Faraday.new(url: @reference.endpoint) do |conn|
    conn.use FaradayMiddleware::FollowRedirects
    conn.adapter Faraday.default_adapter
  end
  begin
    response = connection.get
    return response.body unless response.nil? || response.status == 404
    Geoblacklight.logger.error "Could not reach #{@reference.endpoint}"
    ''
  rescue Faraday::ConnectionFailed, Faraday::TimeoutError, OpenSSL::SSL::SSLError => error
    Geoblacklight.logger.error error.inspect
    ''
  end
end
transformer() click to toggle source

Initialize the MetadataTransformer Object for the metadata @return [GeoBlacklight::MetadataTransformer] MetadataTransformer instance

# File lib/geoblacklight/metadata/base.rb, line 83
def transformer
  MetadataTransformer.instance(self)
end