class Rubabel::MoleculeData
A hash-like interface for dealing with tag data in molecules inspired by the MoleculeData
implementation in pybel. This does not actually hash the data, it just reads it from the OBMol object each time and acts like a hash.
Constants
- DATA_TYPES
- OB_COMMENT_DATA_TYPE
- OB_PAIR_DATA_TYPE
Attributes
obmol[RW]
Public Class Methods
new(obmol)
click to toggle source
# File lib/rubabel/molecule_data.rb, line 18 def initialize(obmol) @obmol = obmol end
Public Instance Methods
[](key)
click to toggle source
# File lib/rubabel/molecule_data.rb, line 48 def [](key) pair_data.find {|pd| pd.get_attribute == key }.get_value end
[]=(key,val)
click to toggle source
returns the val
# File lib/rubabel/molecule_data.rb, line 53 def []=(key,val) if key?(key) OpenBabel.to_pair_data(@obmol.get_data(key)).set_value(val) val else pd = OpenBabel::OBPairData.new pd.set_attribute(key) pd.set_value(val) @obmol.clone_data(pd) val end end
delete(key, &block)
click to toggle source
# File lib/rubabel/molecule_data.rb, line 78 def delete(key, &block) if key?(key) val = self[key] @obmol.delete_data( @obmol.get_data(key) ) val else block ? block.call : nil end end
each(&block)
click to toggle source
# File lib/rubabel/molecule_data.rb, line 32 def each(&block) block or return enum_for(__method__) pair_data.each do |pd| block.call [pd.get_attribute, pd.get_value] end end
key?(key)
click to toggle source
# File lib/rubabel/molecule_data.rb, line 66 def key?(key) pair_data.any? {|pd| pd.get_attribute == key } end
keys()
click to toggle source
# File lib/rubabel/molecule_data.rb, line 70 def keys pair_data.map(&:get_attribute) end
pair_data(&block)
click to toggle source
# File lib/rubabel/molecule_data.rb, line 22 def pair_data(&block) block or return enum_for(__method__) # TODO: should do this with an ob iterator @obmol.get_data.each do |ob_gd| if DATA_TYPES.include?( ob_gd.get_data_type ) block.call( OpenBabel.to_pair_data( ob_gd ) ) end end end
size()
click to toggle source
# File lib/rubabel/molecule_data.rb, line 43 def size pair_data.to_a.size end
Also aliased as: length
to_a()
click to toggle source
# File lib/rubabel/molecule_data.rb, line 39 def to_a each.to_a end
values()
click to toggle source
# File lib/rubabel/molecule_data.rb, line 74 def values pair_data.map(&:get_value) end