Class: Metanorma::Mirror::Model::Factory
- Inherits:
-
Object
- Object
- Metanorma::Mirror::Model::Factory
- Defined in:
- lib/metanorma/mirror/model/factory.rb
Constant Summary collapse
- INVALID_INPUT =
"Factory.from_h expects a Hash, got %<class>s"
Class Method Summary collapse
Class Method Details
.from_h(hash) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/metanorma/mirror/model/factory.rb', line 9 def self.from_h(hash) unless hash.is_a?(Hash) raise ArgumentError, format(INVALID_INPUT, class: hash.class) end type = hash["type"] case type when "text" build_text(hash) when "soft_break" SoftBreak.new when nil raise ArgumentError, "Factory.from_h requires a 'type' key, got #{hash.inspect}" else build_node(hash, type) end end |