Module: OpenBEL::Helpers::Translators

Defined in:
app/openbel/api/helpers/translators.rb

Overview

Helpers for translator functionality based on user’s requested media type.

Class Method Summary collapse

Class Method Details

.for(value) ⇒ BEL::Translator

Find a bel.rb translator plugin by value. The value is commonly the id, file extension, or media type associated with the translator plugin.

Parameters:

  • value (#to_s)

    used to look up translator plugin registered with bel.rb

Returns:

  • (BEL::Translator)

    the translator instance; or nil if one cannot be found



39
40
41
# File 'app/openbel/api/helpers/translators.rb', line 39

def self.for(value)
  BEL.translator(symbolize_value(value))
end

.plugin_for(value) ⇒ Object



43
44
45
# File 'app/openbel/api/helpers/translators.rb', line 43

def self.plugin_for(value)
  BEL::Translator::Plugins.for(symbolize_value(value))
end

.requested_translator(request, params) ⇒ Object



57
58
59
60
61
62
63
64
65
# File 'app/openbel/api/helpers/translators.rb', line 57

def self.requested_translator(request, params)
  if params && params[:format]
    self.for(params[:format])
  else
    request.accept.flat_map { |accept_entry|
      self.for(accept_entry)
    }.compact.first
  end
end

.requested_translator_plugin(request, params) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'app/openbel/api/helpers/translators.rb', line 47

def self.requested_translator_plugin(request, params)
  if params && params[:format]
    self.plugin_for(params[:format])
  else
    request.accept.flat_map { |accept_entry|
      self.plugin_for(accept_entry)
    }.compact.first
  end
end