Class: PubChemAPI::CompoundRecord

Inherits:
APIResponse show all
Defined in:
lib/pubchem_api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ CompoundRecord

Returns a new instance of CompoundRecord.



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/pubchem_api.rb', line 25

def initialize(data)
  super(data)
  compound = data['PC_Compounds'].first
  @cid = compound['id']['id']['cid']

  # Extract properties from the 'props' array
  props = compound['props']
  @molecular_formula = extract_prop(props, 'Molecular Formula')
  @molecular_weight = extract_prop(props, 'Molecular Weight').to_f
  @canonical_smiles = extract_prop(props, 'SMILES', 'Canonical')
  @inchi_key = extract_prop(props, 'InChIKey', 'Standard')
end

Instance Attribute Details

#canonical_smilesObject (readonly)

Returns the value of attribute canonical_smiles.



23
24
25
# File 'lib/pubchem_api.rb', line 23

def canonical_smiles
  @canonical_smiles
end

#cidObject (readonly)

Returns the value of attribute cid.



23
24
25
# File 'lib/pubchem_api.rb', line 23

def cid
  @cid
end

#inchi_keyObject (readonly)

Returns the value of attribute inchi_key.



23
24
25
# File 'lib/pubchem_api.rb', line 23

def inchi_key
  @inchi_key
end

#molecular_formulaObject (readonly)

Returns the value of attribute molecular_formula.



23
24
25
# File 'lib/pubchem_api.rb', line 23

def molecular_formula
  @molecular_formula
end

#molecular_weightObject (readonly)

Returns the value of attribute molecular_weight.



23
24
25
# File 'lib/pubchem_api.rb', line 23

def molecular_weight
  @molecular_weight
end