Class: ROCrate::PreviewGenerator
- Inherits:
-
Object
- Object
- ROCrate::PreviewGenerator
- 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
- #crate ⇒ Object
-
#generate ⇒ String
Generate the crate’s ‘ro-crate-preview.html`.
-
#initialize(preview) ⇒ PreviewGenerator
constructor
A new instance of PreviewGenerator.
- #read(*args) ⇒ Object
- #template ⇒ Object
Constructor Details
#initialize(preview) ⇒ PreviewGenerator
Returns a new instance of PreviewGenerator.
9 10 11 |
# File 'lib/ro_crate/model/preview_generator.rb', line 9 def initialize(preview) @preview = preview end |
Instance Method Details
#crate ⇒ Object
30 31 32 |
# File 'lib/ro_crate/model/preview_generator.rb', line 30 def crate @preview.crate end |
#generate ⇒ String
Generate the crate’s ‘ro-crate-preview.html`.
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 |
#template ⇒ Object
26 27 28 |
# File 'lib/ro_crate/model/preview_generator.rb', line 26 def template @preview.template || ::File.read(Preview::DEFAULT_TEMPLATE) end |