Module: GOBLExtensions::DocumentHelper
- Included in:
- GOBL::Document
- Defined in:
- lib/gobl_extensions/document_helper.rb
Overview
Additional methods for the generated GOBL::Document 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.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/gobl_extensions/document_helper.rb', line 18 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 |