Sha256: beeeafc70c82406c1f74bb65ddbc8c65fb5c4cee1d52802fe2644ba0db8c4fee

Contents?: true

Size: 1.58 KB

Versions: 10

Compression:

Stored size: 1.58 KB

Contents

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

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

      # (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.  Sets the id to the
      # basename.
      def self.[](path, opts={})
        (name, path) = uri_basename_and_path(path)
        self.new(name, name, 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://')
        @id, @name, @location = id, name, location
        params_init
        yield(self) if block_given?
      end

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

      def self.from_xml(xml, ref_hash)
        self.new(xml[:id], xml[:name], xml[:location]).describe_self_from_xml!(xml, ref_hash)
      end

    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
mspire-0.9.2 lib/mspire/mzml/source_file.rb
mspire-0.9.1 lib/mspire/mzml/source_file.rb
mspire-0.9.0 lib/mspire/mzml/source_file.rb
mspire-0.8.7 lib/mspire/mzml/source_file.rb
mspire-0.8.6.2 lib/mspire/mzml/source_file.rb
mspire-0.8.6.1 lib/mspire/mzml/source_file.rb
mspire-0.8.6 lib/mspire/mzml/source_file.rb
mspire-0.8.5 lib/mspire/mzml/source_file.rb
mspire-0.8.4 lib/mspire/mzml/source_file.rb
mspire-0.8.3 lib/mspire/mzml/source_file.rb