Class: Glossarist::V3::HyperedgeWriter
- Inherits:
-
Object
- Object
- Glossarist::V3::HyperedgeWriter
- Defined in:
- lib/glossarist/v3/hyperedge_writer.rb
Overview
HyperedgeWriter — the WRITE half of per-file hyperedge storage.
Mirror of RelationLoader. Each hyperedge is serialized to
relations/<comprehensive-id>/<criterion-slug>.yaml with the
full per-file wire format ($id, type, comprehensive, members,
criterion, sources, notes, status, completeness).
Per-file storage means a single concept (e.g., OIML 5.1
measurement standard) can have N hyperedges (one per criterion),
each in its own file under relations/
Defined Under Namespace
Classes: WriteError
Class Method Summary collapse
-
.write(hyperedge, relations_dir) ⇒ Object
Write a single hyperedge to its per-file location under
relations_dir. -
.write_all(hyperedges, relations_dir) ⇒ Object
Write a batch of hyperedges.
Instance Method Summary collapse
-
#initialize(relations_dir) ⇒ HyperedgeWriter
constructor
A new instance of HyperedgeWriter.
- #write(hyperedge) ⇒ Object
- #write_all(hyperedges) ⇒ Object
Constructor Details
#initialize(relations_dir) ⇒ HyperedgeWriter
Returns a new instance of HyperedgeWriter.
39 40 41 |
# File 'lib/glossarist/v3/hyperedge_writer.rb', line 39 def initialize(relations_dir) @relations_dir = Pathname.new(relations_dir) end |
Class Method Details
.write(hyperedge, relations_dir) ⇒ Object
Write a single hyperedge to its per-file location under
relations_dir. Creates the comprehensive-id subdirectory
if missing. Returns the absolute path written.
27 28 29 |
# File 'lib/glossarist/v3/hyperedge_writer.rb', line 27 def write(hyperedge, relations_dir) new(relations_dir).write(hyperedge) end |
.write_all(hyperedges, relations_dir) ⇒ Object
Write a batch of hyperedges. Returns an Array
34 35 36 |
# File 'lib/glossarist/v3/hyperedge_writer.rb', line 34 def write_all(hyperedges, relations_dir) new(relations_dir).write_all(hyperedges) end |
Instance Method Details
#write(hyperedge) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/glossarist/v3/hyperedge_writer.rb', line 43 def write(hyperedge) raise WriteError, "not an AbstractHyperedge: #{hyperedge.class}" unless hyperedge.is_a?(AbstractHyperedge) path = hyperedge.file_path(@relations_dir) unless path raise WriteError, "cannot derive file path — comprehensive must be non-empty" end FileUtils.mkdir_p(File.dirname(path)) File.write(path, serialize(hyperedge)) path end |
#write_all(hyperedges) ⇒ Object
58 59 60 |
# File 'lib/glossarist/v3/hyperedge_writer.rb', line 58 def write_all(hyperedges) Array(hyperedges).map { |h| write(h) } end |