Module: GOBL::Extensions::Schema::ObjectHelper
- Included in:
- Schema::Object
- Defined in:
- lib/gobl/extensions/schema/object_helper.rb
Overview
Additional methods for the generated Schema::Object class
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#extract ⇒ GOBL::Struct
Extracts the GOBL struct embedded in the document.
-
#schema ⇒ GOBL::ID
Returns the Schema ID of the current document.
Instance Method Details
#extract ⇒ GOBL::Struct
Extracts the GOBL struct embedded in the document. It determines the type of document currently embedded by reading the schema and attemps to instantiate the detected class.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/gobl/extensions/schema/object_helper.rb', line 20 def extract raise 'unknown schema' unless schema.gobl? typs = ['GOBL'] schema.modules.each do |mod| typs << mod.underscore.camelize end typs << schema.name.underscore.camelize klass = typs.join('::').constantize # Sanity check raise "#{klass.name}::SCHEMA_ID expected to be '#{schema}'" unless schema == klass::SCHEMA_ID klass.new _map.except('$schema') end |