Sha256: f07cf7d1416366479ce3284295229681a5cf5615a391f25b074dcd89fe51f07d

Contents?: true

Size: 641 Bytes

Versions: 39

Compression:

Stored size: 641 Bytes

Contents

# frozen_string_literal: true

module Cocina
  module Models
    module Mapping
      # Utility methods for generating purl links
      class Purl
        class_attribute :base_url, default: 'https://purl.stanford.edu'

        def self.for(druid:)
          return nil if druid.nil?

          "#{base_url}/#{druid.delete_prefix('druid:')}"
        end

        def self.purl?(node)
          node.start_with?("https://#{host}") || node.start_with?("http://#{host}")
        end

        # the purl without the protocol part
        def self.host
          @host ||= base_url.sub(%r{^https?://}, '')
        end
      end
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
cocina-models-0.99.1 lib/cocina/models/mapping/purl.rb
cocina-models-0.99.0 lib/cocina/models/mapping/purl.rb
cocina-models-0.98.1 lib/cocina/models/mapping/purl.rb
cocina-models-0.98.0 lib/cocina/models/mapping/purl.rb
cocina-models-0.96.0 lib/cocina/models/mapping/purl.rb
cocina-models-0.95.1 lib/cocina/models/mapping/purl.rb
cocina-models-0.95.0 lib/cocina/models/mapping/purl.rb
cocina-models-0.94.2 lib/cocina/models/mapping/purl.rb
cocina-models-0.94.1 lib/cocina/models/mapping/purl.rb
cocina-models-0.94.0 lib/cocina/models/mapping/purl.rb
cocina-models-0.93.1 lib/cocina/models/mapping/purl.rb
cocina-models-0.93.0 lib/cocina/models/mapping/purl.rb
cocina-models-0.92.0 lib/cocina/models/mapping/purl.rb
cocina-models-0.91.4 lib/cocina/models/mapping/purl.rb
cocina-models-0.91.3 lib/cocina/models/mapping/purl.rb
cocina-models-0.91.2 lib/cocina/models/mapping/purl.rb
cocina-models-0.91.1 lib/cocina/models/mapping/purl.rb
cocina-models-0.91.0 lib/cocina/models/mapping/purl.rb
cocina-models-0.90.0 lib/cocina/models/mapping/purl.rb
cocina-models-0.89.1 lib/cocina/models/mapping/purl.rb