Class: Mspire::Mzml::SourceFile

Inherits:
Object
  • Object
show all
Extended by:
List
Includes:
CV::Paramable
Defined in:
lib/mspire/mzml/source_file.rb

Constant Summary collapse

DEFAULT_SOURCEFILE_ID =
'sourcefile1'

Instance Attribute Summary collapse

Attributes included from CV::Paramable

#cv_params, #ref_param_groups, #user_params

Class Method Summary collapse

Instance Method Summary collapse

Methods included from List

list_xml, list_xml_element

Methods included from CV::Paramable

#accessionable_params, #describe!, #describe_many!, #fetch, #fetch_by_accession, #param?, #param_by_accession, #params, #params?

Constructor Details

#initialize(id = "sourcefile1", name = "mspire-simulated", location = 'file://', opts = {params: []}, &block) ⇒ SourceFile

Returns a new instance of SourceFile.



34
35
36
37
38
# File 'lib/mspire/mzml/source_file.rb', line 34

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

Instance Attribute Details

#idObject

(required) An identifier for this file.



13
14
15
# File 'lib/mspire/mzml/source_file.rb', line 13

def id
  @id
end

#locationObject

(required) URI-formatted location where the file was retrieved.



18
19
20
# File 'lib/mspire/mzml/source_file.rb', line 18

def location
  @location
end

#nameObject

(required) Name of the source file, without reference to location (either URI or local path).



16
17
18
# File 'lib/mspire/mzml/source_file.rb', line 16

def name
  @name
end

Class Method Details

.[](path, opts = {}) ⇒ Object

expands the path and sets the name and location



21
22
23
# File 'lib/mspire/mzml/source_file.rb', line 21

def self.[](path, opts={})
  self.new DEFAULT_SOURCEFILE_ID, *uri_basename_and_path(path)
end

.uri_basename_and_path(file) ⇒ Object

takes a filename (with a relative or expanded path) and returns the uri basename and path suitable for mzml files



27
28
29
30
31
32
# File 'lib/mspire/mzml/source_file.rb', line 27

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

Instance Method Details

#to_xml(builder) ⇒ Object



40
41
42
43
44
45
# File 'lib/mspire/mzml/source_file.rb', line 40

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