Module: BEL::Translator::Plugins

Defined in:
lib/bel/translator.rb,
lib/bel/translator/plugins/rj.rb,
lib/bel/translator/plugins/bnj.rb,
lib/bel/translator/plugins/jgf.rb,
lib/bel/translator/plugins/rdfa.rb,
lib/bel/translator/plugins/trig.rb,
lib/bel/translator/plugins/trix.rb,
lib/bel/translator/plugins/xbel.rb,
lib/bel/translator/plugins/jsonld.rb,
lib/bel/translator/plugins/nquads.rb,
lib/bel/translator/plugins/rdfxml.rb,
lib/bel/translator/plugins/turtle.rb,
lib/bel/translator/plugins/ntriples.rb,
lib/bel/translator/plugins/bnj/translator.rb,
lib/bel/translator/plugins/jgf/translator.rb,
lib/bel/translator/plugins/xbel/translator.rb,
lib/bel/translator/plugins/xbel/xbel_yielder.rb,
lib/bel/translator/plugins/xbel/nanopub_handler.rb,
lib/bel/translator/plugins/xbel/nanopub_yielder.rb

Overview

The Plugins module provides a namespace for translator plugins. Translator plugins must be defined within Plugins in order to be discovered.

Defined Under Namespace

Modules: Bnj, Jgf, Jsonld, Nquads, Ntriples, Rdfa, Rdfxml, Rj, Trig, Trix, Turtle, Xbel

Class Method Summary collapse

Class Method Details

.for(value) ⇒ nil, ...

Retrieves one or more translator plugins that were identified by value.

Parameters:

  • value (#to_s)

    an id, media type, or file extension value that identifies a translator plugin

Returns:

  • (nil)

    when no translator plugin was found

  • (#create_translator)

    when single translator plugin was found

  • (Array<#create_translator>)

    when multiple translator plugins were found



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/bel/translator.rb', line 46

def self.for(value)
  return nil unless value

  value_symbol = value.to_sym
  plugins      = BEL::Translator.plugins

  return plugins[value_symbol] if plugins.include?(value_symbol)

  matches = plugins.values.select { |t|
    match  = false
    match |= (value_symbol == t.name.to_sym)
    match |= (t.media_types.include?(value_symbol))
    match |= (t.file_extensions.include?(value_symbol))
    match
  }

  if matches.empty?
    nil
  elsif matches.size == 1
    matches.first
  else
    matches
  end
end