Class: Relaton::Registry
- Inherits:
-
Object
- Object
- Relaton::Registry
- Includes:
- Singleton
- Defined in:
- lib/relaton/registry.rb
Constant Summary collapse
- SUPPORTED_GEMS =
%w[ relaton_gb relaton_iec relaton_ietf relaton_iso relaton_itu relaton_nist relaton_ogc relaton_calconnect relaton_omg relaton_un relaton_w3c relaton_ieee relaton_iho relaton_bipm relaton_ecma relaton_cie relaton_bsi relaton_cen relaton_iana relaton_3gpp relaton_oasis relaton_doi relaton_jis relaton_xsf relaton_ccsds relaton_etsi relaton_isbn relaton/plateau ].freeze
Instance Attribute Summary collapse
-
#processors ⇒ Object
readonly
Returns the value of attribute processors.
Instance Method Summary collapse
- #[](stdclass) ⇒ Object
-
#by_type(type) ⇒ RelatonIso::Processor, ...
Find processor by type.
-
#class_by_ref(ref) ⇒ Symbol?
Find processor by refernce or prefix.
- #find_processor(short) ⇒ Object
-
#find_processor_by_dataset(dataset) ⇒ Relaton::Processor?
Search a rpocessos by dataset name.
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
-
#processor_by_ref(ref) ⇒ Relaton::Processor
Find processor by reference or prefix.
- #register(processor) ⇒ Object
- #register_gems ⇒ Object
- #require_gem(processor) ⇒ Object
- #supported_processors ⇒ Array<Symbol>
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
20 21 22 23 |
# File 'lib/relaton/registry.rb', line 20 def initialize @processors = {} register_gems end |
Instance Attribute Details
#processors ⇒ Object (readonly)
Returns the value of attribute processors.
18 19 20 |
# File 'lib/relaton/registry.rb', line 18 def processors @processors end |
Instance Method Details
#[](stdclass) ⇒ Object
78 79 80 |
# File 'lib/relaton/registry.rb', line 78 def [](stdclass) require_gem processors[stdclass] end |
#by_type(type) ⇒ RelatonIso::Processor, ...
Find processor by type
74 75 76 |
# File 'lib/relaton/registry.rb', line 74 def by_type(type) require_gem(processors.values.detect { |v| v.prefix == type&.upcase }) end |
#class_by_ref(ref) ⇒ Symbol?
Find processor by refernce or prefix
107 108 109 110 111 112 113 114 115 |
# File 'lib/relaton/registry.rb', line 107 def class_by_ref(ref) ref = ref =~ /^\w+\((.*)\)$/ ? Regexp.last_match(1) : ref @processors.each do |class_name, processor| return class_name if /^(urn:)?#{processor.prefix}\b/i.match?(ref) || processor.defaultprefix.match(ref) end Util.info "`#{ref}` does not have a recognised prefix", key: ref nil end |
#find_processor(short) ⇒ Object
46 47 48 |
# File 'lib/relaton/registry.rb', line 46 def find_processor(short) processors[short.to_sym] end |
#find_processor_by_dataset(dataset) ⇒ Relaton::Processor?
Search a rpocessos by dataset name
62 63 64 |
# File 'lib/relaton/registry.rb', line 62 def find_processor_by_dataset(dataset) require_gem(processors.values.detect { |p| p.datasets&.include? dataset }) end |
#processor_by_ref(ref) ⇒ Relaton::Processor
Find processor by reference or prefix
96 97 98 |
# File 'lib/relaton/registry.rb', line 96 def processor_by_ref(ref) require_gem processors[class_by_ref(ref)] end |
#register(processor) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/relaton/registry.rb', line 36 def register(processor) raise Error unless processor < ::Relaton::Processor p = processor.new return if processors[p.short] Util.debug("processor \"#{p.short}\" registered") processors[p.short] = p end |
#register_gems ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/relaton/registry.rb', line 25 def register_gems # Util.info("Info: detecting backends:") SUPPORTED_GEMS.each do |b| require "#{b}/processor" register Kernel.const_get "#{camel_case(b)}::Processor" rescue LoadError => e Util.error "backend #{b} not present\n#{e.}\n#{e.backtrace.join "\n"}" end end |
#require_gem(processor) ⇒ Object
82 83 84 85 86 87 |
# File 'lib/relaton/registry.rb', line 82 def require_gem(processor) return unless processor require processor.short.to_s processor end |
#supported_processors ⇒ Array<Symbol>
51 52 53 |
# File 'lib/relaton/registry.rb', line 51 def supported_processors processors.keys end |