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 or Mapire::UserParam.
-
#describe_many!(array) ⇒ Object
takes an array of values, each of which is fed into describe!.
-
#fetch(name) ⇒ Object
returns the value if the param exists by that name.
- #fetch_by_accession(acc) ⇒ Object (also: #fetch_by_acc)
- #initialize(opts = {params: []}) ⇒ Object
- #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
26 27 28 |
# File 'lib/mspire/cv/paramable.rb', line 26 def accessionable_params cv_params + ref_param_groups.flat_map(&:params) end |
#describe!(*args) ⇒ Object
Expects arguments describing a single CV::Param or Mapire::UserParam. Will also accept an Nokogiri::XML::Node or Nokogiri::XML::NodeSet
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'
# given an XML::NodeSet
obj.describe! xml_node.xpath('.//cvParam')
# given an XML
obj.describe! xml_node.xpath('.//cvParam').first
returns self
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/mspire/cv/paramable.rb', line 102 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 when Nokogiri::XML::Node # a nokogiri node in particular param = case arg.name when 'cvParam' Mspire::CV::Param[ arg[:accession], arg[:value] ] when 'userParam' Mspire::UserParam.new(arg[:name], arg[:value], arg[:type]) end if (unit_acc = arg[:unitAccession]) param.unit = ::CV::Param.new(arg[:unitCvRef], unit_acc, arg[:unitName]) end @cv_params << param when Nokogiri::XML::NodeSet arg.each {|node| describe!(node) } else if arg.is_a?(Mspire::UserParam) @user_params << arg else (@cv_params << arg) if arg end end self end |
#describe_many!(array) ⇒ Object
takes an array of values, each of which is fed into describe!
76 77 78 79 80 81 82 83 84 |
# File 'lib/mspire/cv/paramable.rb', line 76 def describe_many!(array) array.each do |arg| if arg.is_a?(Array) describe!(*arg) else describe!(arg) end end 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
40 41 42 43 44 45 46 47 |
# File 'lib/mspire/cv/paramable.rb', line 40 def fetch(name) param = params.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
49 50 51 52 53 54 55 56 |
# File 'lib/mspire/cv/paramable.rb', line 49 def fetch_by_accession(acc) param = accessionable_params.find {|v| v.accession == acc } if param param.value || true else false end end |
#initialize(opts = {params: []}) ⇒ Object
63 64 65 66 67 68 |
# File 'lib/mspire/cv/paramable.rb', line 63 def initialize(opts={params: []}) @cv_params = [] @user_params = [] @ref_param_groups = [] describe_many!(opts[:params]) end |
#param?(name) ⇒ Boolean
59 60 61 |
# File 'lib/mspire/cv/paramable.rb', line 59 def param?(name) params.any? {|param| param.name == name } end |
#param_by_accession(acc) ⇒ Object Also known as: param_by_acc
70 71 72 |
# File 'lib/mspire/cv/paramable.rb', line 70 def param_by_accession(acc) accessionable_params.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
19 20 21 22 23 24 |
# File 'lib/mspire/cv/paramable.rb', line 19 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.
134 135 136 137 138 139 140 141 |
# File 'lib/mspire/cv/paramable.rb', line 134 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 |