Project

ro-crate

0.0
The project is in a healthy, maintained state
Create, manipulate, read RO-Crates.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
 Project Readme

ro-crate-ruby

This is a WIP gem for creating, manipulating and reading RO-Crates (conforming to version 1.1 of the specification).

Installation

Using bundler, add the following to your Gemfile:

gem 'ro-crate'

and run bundle install.

Usage

Documentation

Click here for API documentation.

Examples

require 'ro_crate'

# Make a new crate
crate = ROCrate::Crate.new
crate.add_file(File.open('Gemfile')) # Using IO-like objects
crate.add_file('README.md') # or paths

# Quickly add everything from a directory into the crate
crate = ROCrate::Crate.new
crate.add_all('workspace/secret_project/dataset123')

# Write to a zip file
ROCrate::Writer.new(crate).write_zip(File.new('ro_crate.zip', 'w'))

# Write to a directory
ROCrate::Writer.new(crate).write('./ro_crate_stuff')

# Read an RO-Crate
crate = ROCrate::Reader.read('./an_ro_crate_directory')

# Make some changes
existing_file = crate.dereference('some_data.csv')
existing_file.name = 'Some amazing data'
existing_author = existing_file.author
joe = crate.add_person('joe', { name: 'Joe Bloggs' })
file = crate.add_file('some_more_data.csv')
file.author = [joe, existing_author]

# Add an external file
ext_file = crate.add_external_file('https://example.com/my_file.txt')

# Write it back
ROCrate::Writer.new(crate).write('./an_ro_crate_directory')

RO-Crate Preview

A simple HTML preview page is generated when an RO-Crate is written, containing a list of the crate's contents and some metadata. This preview is written to ro-crate-preview.html at the root of the RO-Crate.

The default template can be seen here here.

You can customize this preview by providing your own ERB file. The ERB file is evaluated using the ROCrate::Crate instance's binding.

Example

crate = ROCrate::Crate.new

# ... add stuff to the crate
 
# Tell the crate to use your own template (as a string)
crate.preview.template = File.read('path_to_your_template.html.erb')

# Write it
ROCrate::Writer.new(crate).write('./an_ro_crate_directory')