Sha256: 838377008163fd358873126e3459e01819ef04935c3e7ce578f224bc968ceb4b
Contents?: true
Size: 1.39 KB
Versions: 18
Compression:
Stored size: 1.39 KB
Contents
# frozen_string_literal: true module Geoblacklight module MetadataTransformer ## # Abstract class for transforming geospatial metadata class Base ## # @param [GeoCombine::Metadata] metadata metadata Object # @see GeoCombine::Metadata 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 ## # Returns HTML for the metadata transformed into HTML using GeoCombine # @see GeoCombine::Metadata#to_html # @return [String] the transformed metadata in the HTML def transform cleaned_metadata.to_html rescue => e raise TransformError, e.message end private ## # 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 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 end end end
Version data entries
18 entries across 18 versions & 1 rubygems