Module: ChemScanner::ConfigurationUtil

Defined in:
lib/chem_scanner/configuration/util.rb

Overview

Abbreviation management Singleton

Class Method Summary collapse

Class Method Details

.hash_downcase(hash) ⇒ Object



10
11
12
# File 'lib/chem_scanner/configuration/util.rb', line 10

def self.hash_downcase(hash)
  Hash[hash.map { |key, value| [key.downcase, value] }]
end

.hash_to_lines(hash) ⇒ Object



33
34
35
36
37
38
# File 'lib/chem_scanner/configuration/util.rb', line 33

def self.hash_to_lines(hash)
  lines = [""]
  hash.each { |key, value| lines.push("#{key} #{key} #{value}") }

  lines.join("\n")
end

.read_superatom(path, range = Range.new(0, -1)) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/chem_scanner/configuration/util.rb', line 14

def self.read_superatom(path, range = Range.new(0, -1))
  hash = {}

  File.readlines(path)[range].map do |line|
    fields = line.strip.split(/\s+/)
    next if fields.empty?

    first_char = fields[0][0]
    next if first_char.empty? || first_char == "#"

    first_col = fields.first
    second_col = fields[1]
    hash[first_col.to_sym] = fields[2]
    hash[second_col.to_sym] = fields[2]
  end

  hash
end