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

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.



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

#schemaGOBL::ID

Returns the Schema ID of the current document



11
12
13
# File 'lib/gobl/extensions/schema/object_helper.rb', line 11

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