Module: Mspire::CV::Paramable
- Included in:
- Mzml::Activation, Mzml::Component, Mzml::Contact, Mzml::DataArray, Mzml::DataArrayContainerLike, Mzml::FileContent, Mzml::InstrumentConfiguration, Mzml::IsolationWindow, Mzml::ProcessingMethod, Mzml::ReferenceableParamGroup, Mzml::Run, Mzml::Sample, Mzml::Scan, Mzml::ScanList, Mzml::ScanSettings, Mzml::ScanWindow, Mzml::SelectedIon, Mzml::Software, Mzml::SourceFile
- Defined in:
- lib/mspire/cv/paramable.rb
Instance Attribute Summary collapse
-
#cv_params ⇒ Object
Returns the value of attribute cv_params.
-
#ref_param_groups ⇒ Object
Returns the value of attribute ref_param_groups.
-
#user_params ⇒ Object
Returns the value of attribute user_params.
Instance Method Summary collapse
- #accessionable_params ⇒ Object
-
#describe!(*args) ⇒ Object
Expects arguments describing a single CV::Param, Mspire::UserParam, or Mspire::Mzml::ReferenceableParamGroup.
-
#describe_from_xml!(xml_node, ref_hash = nil) ⇒ Object
takes a node with children that are cvParam, userParam or referenceableParamGroupRef and a hash containing referenceableParamGroup objects indexed by id.
-
#describe_many!(array) ⇒ Object
takes an array of values, each of which is fed into describe! returns self.
-
#describe_self_from_xml!(xml_node, ref_hash = nil) ⇒ Object
reads the paramable nodes and returns self.
- #each_accessionable_param(&block) ⇒ Object
- #each_param(&block) ⇒ Object
-
#fetch(name) ⇒ Object
returns the value if the param exists by that name.
- #fetch_by_accession(acc) ⇒ Object (also: #fetch_by_acc)
- #initialize ⇒ Object (also: #params_init)
- #param?(name) ⇒ Boolean
- #param_by_accession(acc) ⇒ Object (also: #param_by_acc)
- #params ⇒ Object
- #params? ⇒ Boolean
-
#to_xml(xml) ⇒ Object
iterates over @params and calls .to_xml on each object.
Instance Attribute Details
#cv_params ⇒ Object
Returns the value of attribute cv_params.
11 12 13 |
# File 'lib/mspire/cv/paramable.rb', line 11 def cv_params @cv_params end |
#ref_param_groups ⇒ Object
Returns the value of attribute ref_param_groups.
13 14 15 |
# File 'lib/mspire/cv/paramable.rb', line 13 def ref_param_groups @ref_param_groups end |
#user_params ⇒ Object
Returns the value of attribute user_params.
12 13 14 |
# File 'lib/mspire/cv/paramable.rb', line 12 def user_params @user_params end |
Instance Method Details
#accessionable_params ⇒ Object
41 42 43 |
# File 'lib/mspire/cv/paramable.rb', line 41 def accessionable_params cv_params + ref_param_groups.flat_map(&:params) end |
#describe!(*args) ⇒ Object
Expects arguments describing a single CV::Param, Mspire::UserParam, or Mspire::Mzml::ReferenceableParamGroup
obj.describe! 'MS:1000130' # a positive scan
obj.describe! CV::Param['MS:1000130'] # same behavior
# base peak intensity, units=number of counts
obj.describe! "MS:1000505", 1524.5865478515625, 'MS:1000131'
returns self
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/mspire/cv/paramable.rb', line 153 def describe!(*args) return self if args.first.nil? case (arg=args.first) when String @cv_params << Mspire::CV::Param[ *args ] when Mspire::Mzml::ReferenceableParamGroup @ref_param_groups << arg else if arg.is_a?(Mspire::UserParam) @user_params << arg else @cv_params << arg end end self end |
#describe_from_xml!(xml_node, ref_hash = nil) ⇒ Object
takes a node with children that are cvParam, userParam or referenceableParamGroupRef and a hash containing referenceableParamGroup objects indexed by id. The only time ref_hash should be left nil is for the referenceableParamGroup itself.
All param elements are required to appear before other elements, so the code walks through each child node to see if it is a paramable element. The first child node that is not paramable is returned (or nil if none)
returns the next child node after the paramable elements or nil if none
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/mspire/cv/paramable.rb', line 121 def describe_from_xml!(xml_node, ref_hash=nil) return nil unless (child_n = xml_node.child) loop do array = case child_n.name when 'referenceableParamGroupRef' @ref_param_groups << ref_hash[child_n[:ref]] when 'cvParam' @cv_params << Mspire::CV::Param[ child_n[:accession], child_n[:value] ] when 'userParam' @user_params << Mspire::UserParam.new(child_n[:name], child_n[:value], child_n[:type]) else # assumes that the above precede any following children as per the spec break end if (unit_acc = child_n[:unitAccession]) array.last.unit = ::CV::Param.new(child_n[:unitCvRef], unit_acc, child_n[:unitName]) end break unless child_n = child_n.next end child_n end |
#describe_many!(array) ⇒ Object
takes an array of values, each of which is fed into describe! returns self.
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/mspire/cv/paramable.rb', line 92 def describe_many!(array) array.each do |arg| if arg.is_a?(Array) describe!(*arg) else describe!(arg) end end self end |
#describe_self_from_xml!(xml_node, ref_hash = nil) ⇒ Object
reads the paramable nodes and returns self. Use this if your element does not have anything besides paramable elements.
105 106 107 108 |
# File 'lib/mspire/cv/paramable.rb', line 105 def describe_self_from_xml!(xml_node, ref_hash=nil) describe_from_xml!(xml_node, ref_hash) self end |
#each_accessionable_param(&block) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/mspire/cv/paramable.rb', line 34 def each_accessionable_param(&block) return enum_for __method__ unless block cv_params.each(&block) ref_param_groups.flat_map(&:params).each(&block) nil end |
#each_param(&block) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/mspire/cv/paramable.rb', line 19 def each_param(&block) return enum_for __method__ unless block cv_params.each(&block) ref_param_groups.flat_map(&:params).each(&block) user_params.each(&block) nil end |
#fetch(name) ⇒ Object
returns the value if the param exists by that name. Returns true if the param exists but has no value. returns false if no param
55 56 57 58 59 60 61 62 |
# File 'lib/mspire/cv/paramable.rb', line 55 def fetch(name) param = each_param.find {|param| param.name == name} if param param.value || true else false end end |
#fetch_by_accession(acc) ⇒ Object Also known as: fetch_by_acc
64 65 66 67 68 69 70 71 |
# File 'lib/mspire/cv/paramable.rb', line 64 def fetch_by_accession(acc) param = accessionable_params.find {|v| v.accession == acc } if param param.value || true else false end end |
#initialize ⇒ Object Also known as: params_init
78 79 80 81 82 |
# File 'lib/mspire/cv/paramable.rb', line 78 def initialize @cv_params = [] @user_params = [] @ref_param_groups = [] end |
#param?(name) ⇒ Boolean
74 75 76 |
# File 'lib/mspire/cv/paramable.rb', line 74 def param?(name) params.any? {|param| param.name == name } end |
#param_by_accession(acc) ⇒ Object Also known as: param_by_acc
85 86 87 |
# File 'lib/mspire/cv/paramable.rb', line 85 def param_by_accession(acc) each_accessionable_param.find {|v| v.accession == acc } end |
#params ⇒ Object
15 16 17 |
# File 'lib/mspire/cv/paramable.rb', line 15 def params cv_params + ref_param_groups.flat_map(&:params) + user_params end |
#params? ⇒ Boolean
27 28 29 30 31 32 |
# File 'lib/mspire/cv/paramable.rb', line 27 def params? total_num_params = cv_params.size + ref_param_groups.reduce(0) {|sum,group| sum + group.params.size } + user_params.size total_num_params > 0 end |
#to_xml(xml) ⇒ Object
iterates over @params and calls .to_xml on each object.
171 172 173 174 175 176 177 178 |
# File 'lib/mspire/cv/paramable.rb', line 171 def to_xml(xml) [:ref_param_groups, :cv_params, :user_params].each do |kind| self.send(kind).each do |obj| obj.to_xml(xml) end end xml end |