Class: Mspire::Mzml::SourceFile

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

Instance Attribute Summary collapse

Attributes included from 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 Paramable

#accessionable_params, #describe!, #describe_from_xml!, #describe_many!, #describe_self_from_xml!, #each_accessionable_param, #each_param, #fetch, #fetch_by_accession, #param?, #param_by_accession, #params, #params?, #reject!, #replace!, #replace_many!

Constructor Details

#initialize(id = "sourcefile1", name = "mspire-simulated", location = 'file://') {|_self| ... } ⇒ SourceFile

Returns a new instance of SourceFile.

Yields:

  • (_self)

Yield Parameters:



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

def initialize(id="sourcefile1", name="mspire-simulated", location='file://')
  @id, @name, @location = id, name, location
  params_init
  yield(self) if block_given?
end

Instance Attribute Details

#idObject

(required) An identifier for this file.



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

def id
  @id
end

#locationObject

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



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

def location
  @location
end

#nameObject

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



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

def name
  @name
end

Class Method Details

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

expands the path and sets the name and location. Sets the id to the basename.



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

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

.from_xml(xml, ref_hash) ⇒ Object



48
49
50
# File 'lib/mspire/mzml/source_file.rb', line 48

def self.from_xml(xml, ref_hash)
  self.new(xml[:id], xml[:name], xml[:location]).describe_self_from_xml!(xml, ref_hash)
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



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

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



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

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