Class: AsciiChem::Model::Spectrum

Inherits:
Node
  • Object
show all
Defined in:
lib/asciichem/model/spectrum.rb

Overview

A spectroscopy result: NMR, IR, MS, UV-Vis peaks.

Syntax:

spectrum[nmr](type=1H,solvent=CDCl3){
1.2: 3H s "CH3"
7.2: 5H m "C6H5"
}

spectrum[ir]{
3300: broad "O-H stretch"
}

spectrum[ms]{
18: 100% "M+"
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Node

#==, #accept, #hash, short_name, #to_cml, #to_html, #to_latex, #to_mathml, #to_svg, #to_text

Constructor Details

#initialize(type: nil, params: {}, peaks: []) ⇒ Spectrum

Returns a new instance of Spectrum.



23
24
25
26
27
# File 'lib/asciichem/model/spectrum.rb', line 23

def initialize(type: nil, params: {}, peaks: [])
  @type = type
  @params = params
  @peaks = peaks
end

Instance Attribute Details

#paramsObject

Returns the value of attribute params.



21
22
23
# File 'lib/asciichem/model/spectrum.rb', line 21

def params
  @params
end

#peaksObject

Returns the value of attribute peaks.



21
22
23
# File 'lib/asciichem/model/spectrum.rb', line 21

def peaks
  @peaks
end

#typeObject

Returns the value of attribute type.



21
22
23
# File 'lib/asciichem/model/spectrum.rb', line 21

def type
  @type
end

Instance Method Details

#childrenObject



33
34
35
# File 'lib/asciichem/model/spectrum.rb', line 33

def children
  []
end

#diagnostic_labelObject



37
38
39
# File 'lib/asciichem/model/spectrum.rb', line 37

def diagnostic_label
  "Spectrum(#{type || 'unknown'})"
end

#to_sObject



41
42
43
# File 'lib/asciichem/model/spectrum.rb', line 41

def to_s
  "spectrum[#{type}](#{params.map { |k, v| "#{k}=#{v}" }.join(',')})"
end

#value_attributesObject



29
30
31
# File 'lib/asciichem/model/spectrum.rb', line 29

def value_attributes
  { type: type, params: params, peaks: peaks }
end