Class: Cocina::Generator::Vocab
- Inherits:
-
Object
- Object
- Cocina::Generator::Vocab
- Defined in:
- lib/cocina/generator/vocab.rb
Overview
Class for generating a vocab
Constant Summary collapse
- CLASS_COMMENT =
{ 'ObjectType' => 'This vocabulary defines the top level object type', 'FileSetType' => 'This vocabulary defines the types of file sets' }.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #contents(namespace, methods) ⇒ Object
- #generate ⇒ Object
-
#initialize(schemas, output_dir:) ⇒ Vocab
constructor
A new instance of Vocab.
Constructor Details
#initialize(schemas, output_dir:) ⇒ Vocab
Returns a new instance of Vocab.
16 17 18 19 |
# File 'lib/cocina/generator/vocab.rb', line 16 def initialize(schemas, output_dir:) @schemas = schemas @output_dir = output_dir end |
Class Method Details
.generate(schemas, output_dir:) ⇒ Object
12 13 14 |
# File 'lib/cocina/generator/vocab.rb', line 12 def self.generate(schemas, output_dir:) new(schemas, output_dir: output_dir).generate end |
Instance Method Details
#contents(namespace, methods) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/cocina/generator/vocab.rb', line 28 def contents(namespace, methods) <<~RUBY # frozen_string_literal: true module Cocina module Models # #{CLASS_COMMENT.fetch(namespace)} class #{namespace} < Vocabulary('#{URIS.fetch(namespace)}') #{draw_ruby_methods(methods, 6)} end end end RUBY end |
#generate ⇒ Object
21 22 23 24 25 26 |
# File 'lib/cocina/generator/vocab.rb', line 21 def generate names.each do |namespace, v| filepath = File.join(output_dir, "#{namespace.underscore}.rb") File.write(filepath, contents(namespace, v)) end end |