class Geoblacklight::MetadataTransformer::Base

Abstract class for transforming geospatial metadata

Public Class Methods

new(metadata) click to toggle source

@param [GeoCombine::Metadata] metadata metadata Object @see GeoCombine::Metadata

# File lib/geoblacklight/metadata_transformer/base.rb, line 11
def initialize(metadata)
  @metadata = metadata
  # Access the Nokogiri::XML Document from the metadata Object
  fail EmptyMetadataError, "Failed to retrieve the metadata" if @metadata.blank?
end

Public Instance Methods

transform() click to toggle source

Returns HTML for the metadata transformed into HTML using GeoCombine @see GeoCombine::Metadata#to_html @return [String] the transformed metadata in the HTML

# File lib/geoblacklight/metadata_transformer/base.rb, line 21
def transform
  cleaned_metadata.to_html
rescue => e
  raise TransformError, e.message
end

Private Instance Methods

cleaned_metadata() click to toggle source

Clean top-level HTML elements from GeoCombine HTML Documents (e. g. <html> and <body>) @return [Nokogiri::XML::Document] the Nokogiri XML Document for the cleaned HTML

# File lib/geoblacklight/metadata_transformer/base.rb, line 32
def cleaned_metadata
  transformed_doc = Nokogiri::XML(@metadata.to_html)
  if transformed_doc.xpath("//body").children.empty?
    fail TransformError,
      "Failed to extract the <body> child elements from the transformed metadata"
  end
  transformed_doc.xpath("//body").children
rescue => e
  raise TransformError, e.message
end