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

Instance Method Details

#extractGOBL::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.

Returns:

  • (GOBL::Struct)

    the GOBL struct embedded in the document



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

#schemaGOBL::ID

Returns the Schema ID of the current document

Returns:



9
10
11
# File 'lib/gobl_extensions/document_helper.rb', line 9

def schema
  @schema ||= GOBL::ID.new(_map['$schema'])
end