Sha256: f3197d6e0e4017aaeaa45fd3a6de5d3da64804417cfd0171c56d0eaac68fab68

Contents?: true

Size: 1.87 KB

Versions: 17

Compression:

Stored size: 1.87 KB

Contents

require 'bel_parser/quoting'

# Serializing of common {BEL::Nanopub::Nanopub nanopub} components to BEL
# Script syntax.
#
# @abstract
module BEL::Translator::Plugins::BelScript::NanopubSerialization
  include BELParser::Quoting

  # Serialize the {BEL::Nanopub::Nanopub nanopub} to a BEL Script string.
  #
  # @param  [BEL::Nanopub::Nanopub] nanopub the nanopub to serialize
  # @return [String]               the BEL Script string
  # @abstract Include and override {#to_bel} to implement serialization
  #           {BEL::Nanopub::Nanopub nanopub} to BEL Script
  def to_bel(nanopub)
  end

  # Return BEL Script syntax that completes the BEL Script document.
  #
  # @abstract
  def epilogue
    raise NotImplementedError.new("#{self.class}#epilogue")
  end

  protected

  def citation_value(nanopub)
    citation = nanopub.citation

    return nil unless citation && citation.valid?

    values = citation.to_a
    values.map! { |v|
      v = %("") if v.nil? || v.empty?
      if v.respond_to?(:each)
        v.map! { |item| item.delete("\r\n") }
        quote(v.join('|'))
      else
        v.delete!("\r\n")
        quote(v)
      end
    }
    values.join(', ')
  end

  def support_value(nanopub)
    support = nanopub.support

    return nil unless support && support.value

    value = support.value
    value.gsub!("\n", "")
    value.gsub!('"', %Q{\\"})
    value
  end

  def annotation_values(nanopub)
    experiment_context = nanopub.experiment_context

    return {} unless experiment_context

    Hash[
      experiment_context.
        sort_by { |obj| obj[:name].to_sym }.
        map { |obj|
          name  = obj[:name].to_sym
          value = obj[:value]

          value_s =
            if value.respond_to? :map
              "{#{value.map { |v| quote(v) }.join(', ')}}"
            else
              quote(value)
            end

          [name, value_s]
        }
    ]
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
bel_parser-1.1.6-java lib/bel/translator/plugins/bel_script/nanopub_serialization.rb
bel_parser-1.1.6 lib/bel/translator/plugins/bel_script/nanopub_serialization.rb
bel_parser-1.1.5 lib/bel/translator/plugins/bel_script/nanopub_serialization.rb
bel_parser-1.1.4-java lib/bel/translator/plugins/bel_script/nanopub_serialization.rb
bel_parser-1.1.4 lib/bel/translator/plugins/bel_script/nanopub_serialization.rb
bel_parser-1.1.3-java lib/bel/translator/plugins/bel_script/nanopub_serialization.rb
bel_parser-1.1.3 lib/bel/translator/plugins/bel_script/nanopub_serialization.rb
bel_parser-1.1.2-java lib/bel/translator/plugins/bel_script/nanopub_serialization.rb
bel_parser-1.1.2 lib/bel/translator/plugins/bel_script/nanopub_serialization.rb
bel_parser-1.1.1-java lib/bel/translator/plugins/bel_script/nanopub_serialization.rb
bel_parser-1.1.1 lib/bel/translator/plugins/bel_script/nanopub_serialization.rb
bel_parser-1.0.8-java lib/bel/translator/plugins/bel_script/nanopub_serialization.rb
bel_parser-1.0.8 lib/bel/translator/plugins/bel_script/nanopub_serialization.rb
bel_parser-1.0.7-java lib/bel/translator/plugins/bel_script/nanopub_serialization.rb
bel_parser-1.0.7 lib/bel/translator/plugins/bel_script/nanopub_serialization.rb
bel_parser-1.0.6-java lib/bel/translator/plugins/bel_script/nanopub_serialization.rb
bel_parser-1.0.6 lib/bel/translator/plugins/bel_script/nanopub_serialization.rb