Module: BEL::Translator

Overview

The Translator module defines a plugin that reads a specific document format into BEL nanopubs and writes BEL nanopubs back to this document format.

Examples:

Create a translator for conversion of YAML <-> BEL nanopub.

module Translator

  include ::BEL::Translator

  def read(data, options = {})
    objects = YAML.load(data)
    # map objects to BEL nanopub
    # return enumerator
  end

  def write(data, writer = nil, options = {})
    # map BEL nanopub to YAML objects
    YAML.dump(data)
  end
end

Defined Under Namespace

Modules: Plugins

Instance Method Summary collapse

Instance Method Details

#read(data, options = {}) ⇒ #each

Read BEL nanopubs from this translator’s supported file format.

Parameters:

  • data (IO, String)

    the data to read

  • options (Hash{Symbol => Object}) (defaults to: {})

Returns:

  • (#each)

    an object that responds to each and provides Nanopub::Nanopub objects

Raises:

  • (NotImplementedError)


89
90
91
# File 'lib/bel/translator.rb', line 89

def read(data, options = {})
  raise NotImplementedError.new("#{__method__} is not implemented.")
end

#write(data, writer = StringIO.new, options = {}) ⇒ IO

Writes BEL nanopubs to the provided IO writer.

Parameters:

  • data (#each)

    an object that responds to each and provides Nanopub::Nanopub objects

  • writer (IO) (defaults to: StringIO.new)

    an IO to write to

  • options (Hash{Symbol => Object}) (defaults to: {})

Returns:

  • (IO)

    the IO that was written to

Raises:

  • (NotImplementedError)


100
101
102
# File 'lib/bel/translator.rb', line 100

def write(data, writer = StringIO.new, options = {})
  raise NotImplementedError.new("#{__method__} is not implemented.")
end