Sha256: b979a3239e4f712d07ecdb42e284b63f6f4f8d2bba002547b6f9748da66908c4

Contents?: true

Size: 1.21 KB

Versions: 2

Compression:

Stored size: 1.21 KB

Contents

module ROCrate
  ##
  # A class to represent a "Data Entity" within an RO Crate.
  # Data Entities are the actual physical files and directories within the Crate.
  class DataEntity < Entity
    def self.format_id(id)
      super.chomp('/')
    end

    ##
    # Return an appropriate specialization of DataEntity for the given properties.
    # @param props [Hash] Set of properties to try and infer the type from.
    # @return [Class]
    def self.specialize(props)
      type = props['@type']
      id = props['@id']
      abs = URI(id)&.absolute? rescue false
      type = [type] unless type.is_a?(Array)
      if type.include?('Dataset')
        ROCrate::Directory
      else
        ROCrate::File
      end
    end

    ##
    # A map of all the files/directories associated with this DataEntity.
    #
    # @return [Hash{String => Entry}>] The key is the location within the crate, and the value is an Entry.
    def entries
      {}
    end

    ##
    # A disk-safe filepath based on the ID of this DataEntity.
    #
    # @return [String] The relative file path of this DataEntity within the Crate.
    def filepath
      Addressable::URI.unescape(id.sub(/\A\//, '')).to_s # Remove initial / and decode %20 etc.
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ro-crate-0.4.1 lib/ro_crate/model/data_entity.rb
ro-crate-0.4.0 lib/ro_crate/model/data_entity.rb