Sha256: f8036eacd65f1d859796358af61fcba47d64a791c4ebc7c46d77bd5b51fab106

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 KB

Contents

require 'ms/cv/param'

module MS
  module CV
    # An MS::Description is a convenient way to specify several mass spec related
    # cvParam objects at once. 
    #
    # examples of usage:
    #
    #     Description.new( <CV::Param> )
    #     Description['MS:1000004', ['MS:1000004'], ['IMS:1000042', 23], param_obj, args]
    #     Description.new do
    #       param MS:1000004
    #       param MS:1000042, 23
    #     end
    class Description < Array

      # ensures that each argument is an argument that can be handled by
      # CV::Param. Returns the Description object it creates
      def self.[](*args)
        list = self.new
        args.each do |arg| 
          arg.is_a?(Array) ? list.param(*arg) : list.param(arg) 
        end
        list
      end

      # takes a list of valid CV::Param objects, or they can be set in the block
      # using param
      def initialize(*args, &block)
        args.each {|arg| param(arg) }
        instance_eval &block if block
      end

      # if the first object is a MS::CV::Param it is just pushed onto the list,
      # otherwise the arguments are sent in to initialize a fresh MS::CV::Param,
      # and this object is pushed onto the list.
      def param(*args)
        push args.first.is_a?(::CV::Param) ? args.first : MS::CV::Param.new(*args)
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mspire-0.6.7 lib/ms/cv/description.rb