Sha256: 334186ca090e3439fe7f144e99ab40c5b3f5e66811ad8b3b5bee65a9067b37c6

Contents?: true

Size: 1.46 KB

Versions: 9

Compression:

Stored size: 1.46 KB

Contents

require 'mspire/cv/paramable'
require 'mspire/mzml/list'
require 'pathname'

module Mspire
  class Mzml
    class SourceFile
      include Mspire::CV::Paramable

      DEFAULT_SOURCEFILE_ID = 'sourcefile1'

      # (required) An identifier for this file.
      attr_accessor :id
      # (required) Name of the source file, without reference to location
      # (either URI or local path).
      attr_accessor :name
      # (required) URI-formatted location where the file was retrieved.
      attr_accessor :location

      # expands the path and sets the name and location
      def self.[](path, opts={})
        self.new DEFAULT_SOURCEFILE_ID, *uri_basename_and_path(path)
      end

      # takes a filename (with a relative or expanded path) and returns the
      # uri basename and path suitable for mzml files
      def self.uri_basename_and_path(file)
        pathname = Pathname.new(file)
        dir = pathname.expand_path.dirname.to_s
        dir = '/'+dir unless (dir[0] == '/')
        [pathname.basename, 'file://'+ dir]
      end

      def initialize(id="sourcefile1", name="mspire-simulated", location='file://', opts={params: []}, &block)
        @id, @name, @location = id, name, location
        super(opts)
        block.call(self) if block
      end

      def to_xml(builder)
        builder.sourceFile( id: @id, name: @name, location: @location ) do |sf_n|
          super(sf_n)
        end
        builder
      end

      extend(Mspire::Mzml::List)
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
mspire-0.7.18 lib/mspire/mzml/source_file.rb
mspire-0.7.17 lib/mspire/mzml/source_file.rb
mspire-0.7.13 lib/mspire/mzml/source_file.rb
mspire-0.7.12 lib/mspire/mzml/source_file.rb
mspire-0.7.11 lib/mspire/mzml/source_file.rb
mspire-0.7.10 lib/mspire/mzml/source_file.rb
mspire-0.7.9 lib/mspire/mzml/source_file.rb
mspire-0.7.8 lib/mspire/mzml/source_file.rb
mspire-0.7.7 lib/mspire/mzml/source_file.rb