Class: Metanorma::Registry

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/metanorma/registry/registry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRegistry

Returns a new instance of Registry.



14
15
16
17
# File 'lib/metanorma/registry/registry.rb', line 14

def initialize
  @processors = {}
  @aliases = { csd: :cc, m3d: :m3aawg, mpfd: :mpfa, csand: :csa }
end

Instance Attribute Details

#processorsObject (readonly)

Returns the value of attribute processors.



12
13
14
# File 'lib/metanorma/registry/registry.rb', line 12

def processors
  @processors
end

Instance Method Details

#alias(flavour) ⇒ Object



19
20
21
# File 'lib/metanorma/registry/registry.rb', line 19

def alias(flavour)
  @aliases[flavour]
end

#find_processor(short) ⇒ Object



38
39
40
# File 'lib/metanorma/registry/registry.rb', line 38

def find_processor(short)
  @processors[short.to_sym]
end

#output_formatsObject



46
47
48
49
50
51
# File 'lib/metanorma/registry/registry.rb', line 46

def output_formats
  @processors.inject({}) do |acc, (k, v)|
    acc[k] = v.output_formats
    acc
  end
end

#register(processor) ⇒ Object

Raises:



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/metanorma/registry/registry.rb', line 23

def register(processor)
  raise Error unless processor < ::Metanorma::Processor

  p = processor.new
  # p.short[-1] is the canonical name
  short = Array(p.short)
  @processors[short[-1]] = p
  short.each do |s|
    @aliases[s] = short[-1]
  end
  Array(p.short)
  Util.log("[metanorma] processor \"#{Array(p.short)[0]}\" registered",
           :info)
end

#root_tagsObject



53
54
55
56
57
58
59
60
61
# File 'lib/metanorma/registry/registry.rb', line 53

def root_tags
  @processors.inject({}) do |acc, (k, v)|
    if v.asciidoctor_backend
      x = Asciidoctor.load nil, { backend: v.asciidoctor_backend }
      acc[k] = x.converter.xml_root_tag
    end
    acc
  end
end

#supported_backendsObject



42
43
44
# File 'lib/metanorma/registry/registry.rb', line 42

def supported_backends
  @processors.keys
end