Class: Chemicalml::Cli::InfoCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/chemicalml/cli/info_command.rb

Overview

chemicalml info <element> — show details about a CML element by XML name: Ruby class, role, attributes, applicable constraints.

Instance Attribute Summary

Attributes inherited from Command

#logger

Instance Method Summary collapse

Methods inherited from Command

#initialize, run

Constructor Details

This class inherits a constructor from Chemicalml::Cli::Command

Instance Method Details

#run(options) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/chemicalml/cli/info_command.rb', line 8

def run(options)
  name = options[:element]
  unless name
    logger.error 'info requires an <element-name> argument (e.g. "atom")'
    return 2
  end

  klass = Chemicalml::Cml.for_xml_name(name)
  unless klass
    stderr "unknown element: #{name}"
    return 2
  end

  Chemicalml::Cml::Schema3::Configuration.ensure_registered!
  puts "Element: <#{name}>"
  puts "Class:   #{klass}"
  role = role_of(klass)
  puts "Role:    #{role || '(none)'}"
  puts ''
  puts "Attributes (#{klass.attributes.size}):"
  klass.attributes.each_value do |attr|
    col = attr.collection? ? '[]' : ' '
    puts "  #{attr.name}#{col}"
  end
  applicable = constraints_for_role(role)
  return 0 if applicable.empty?

  puts ''
  puts "Applicable constraints (#{applicable.size}):"
  applicable.each do |(conv, c)|
    puts "  [#{conv.qname}] #{c.name.split('::').last}"
  end
  0
end