module BEL::Translator::Plugins::BelScript::NanopubSerialization

Serializing of common {BEL::Nanopub::Nanopub nanopub} components to BEL Script syntax.

@abstract

Public Instance Methods

epilogue() click to toggle source

Return BEL Script syntax that completes the BEL Script document.

@abstract

# File lib/bel/translator/plugins/bel_script/nanopub_serialization.rb, line 22
def epilogue
  raise NotImplementedError.new("#{self.class}#epilogue")
end
to_bel(nanopub) click to toggle source

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
# File lib/bel/translator/plugins/bel_script/nanopub_serialization.rb, line 16
def to_bel(nanopub)
end

Protected Instance Methods

annotation_values(nanopub) click to toggle source
# File lib/bel/translator/plugins/bel_script/nanopub_serialization.rb, line 58
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
citation_value(nanopub) click to toggle source
# File lib/bel/translator/plugins/bel_script/nanopub_serialization.rb, line 28
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
support_value(nanopub) click to toggle source
# File lib/bel/translator/plugins/bel_script/nanopub_serialization.rb, line 47
def support_value(nanopub)
  support = nanopub.support

  return nil unless support && support.value

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