Class: AsciiChem::Model::Bond

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

Overview

A bond between two adjacent nodes in a structural chain.

Constant Summary collapse

KINDS =
{
  single:    { ascii: "-",  mathml_entity: "-" },
  double:    { ascii: "=",  mathml_entity: "=" },
  triple:    { ascii: "#",  mathml_entity: "" },
  quadruple: { ascii: "##", mathml_entity: "" },
  wedge:     { ascii: ">-", mathml_entity: "" },
  hash:      { ascii: "-<", mathml_entity: "" },
  dative:    { ascii: "~>", mathml_entity: "" },
  wavy:      { ascii: "~~", mathml_entity: "" }
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Node

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

Constructor Details

#initialize(kind: :single) ⇒ Bond

Returns a new instance of Bond.



20
21
22
# File 'lib/asciichem/model/bond.rb', line 20

def initialize(kind: :single)
  @kind = kind
end

Instance Attribute Details

#kindObject

Returns the value of attribute kind.



7
8
9
# File 'lib/asciichem/model/bond.rb', line 7

def kind
  @kind
end

Instance Method Details

#asciiObject



28
29
30
# File 'lib/asciichem/model/bond.rb', line 28

def ascii
  KINDS.fetch(kind).fetch(:ascii)
end

#entityObject



32
33
34
# File 'lib/asciichem/model/bond.rb', line 32

def entity
  KINDS.fetch(kind).fetch(:mathml_entity)
end

#to_sObject



36
37
38
# File 'lib/asciichem/model/bond.rb', line 36

def to_s
  "Bond(#{kind})"
end

#value_attributesObject



24
25
26
# File 'lib/asciichem/model/bond.rb', line 24

def value_attributes
  { kind: kind }
end