Class: ROCrate::PreviewGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/ro_crate/model/preview_generator.rb

Overview

A class to handle generation of an RO-Crate’s preview HTML in an IO-like way (to fit into an Entry).

Instance Method Summary collapse

Constructor Details

#initialize(preview) ⇒ PreviewGenerator

Returns a new instance of PreviewGenerator.

Parameters:

  • preview (Preview)

    The RO-Crate preview object.



9
10
11
# File 'lib/ro_crate/model/preview_generator.rb', line 9

def initialize(preview)
  @preview = preview
end

Instance Method Details

#crateObject



30
31
32
# File 'lib/ro_crate/model/preview_generator.rb', line 30

def crate
  @preview.crate
end

#generateString

Generate the crate’s ‘ro-crate-preview.html`.

Returns:

  • (String)

    The rendered HTML as a string.



20
21
22
23
24
# File 'lib/ro_crate/model/preview_generator.rb', line 20

def generate
  b = crate.get_binding
  renderer = ERB.new(template)
  renderer.result(b)
end

#read(*args) ⇒ Object



13
14
15
# File 'lib/ro_crate/model/preview_generator.rb', line 13

def read(*args)
  io.read(*args)
end

#templateObject



26
27
28
# File 'lib/ro_crate/model/preview_generator.rb', line 26

def template
  @preview.template || ::File.read(Preview::DEFAULT_TEMPLATE)
end