Module: Chemicalml::Dictionary::Loader

Defined in:
lib/chemicalml/dictionary/loader.rb

Overview

Reads a YAML file conforming to the dictionary schema (see TODO.cml-full/05-dictionary-layer.md) and constructs a Chemicalml::Dictionary::Model.

This is the only place that knows about the YAML wire shape — everything else works in terms of the canonical Model.

Class Method Summary collapse

Class Method Details

.from_file(path) ⇒ Object



14
15
16
# File 'lib/chemicalml/dictionary/loader.rb', line 14

def self.from_file(path)
  from_hash(YAML.load_file(path))
end

.from_hash(hash) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/chemicalml/dictionary/loader.rb', line 18

def self.from_hash(hash)
  Model.new(
    namespace: hash.fetch("namespace"),
    prefix: hash.fetch("prefix"),
    title: hash.fetch("title"),
    description: hash["description"],
    entries: (hash["entries"] || []).map { |e| build_entry(e) }
  )
end