class DwCR::Metaschema::Archive

This class represents the DarwinCoreArchive's meta.xml file

Public Instance Methods

load_nodes_from(xml) click to toggle source

Gets core and extension nodes from the xml calls add_entity_from(xml) to create Entity instances to the Archive for every node adds the foreign key field (coreid) to any extension

# File lib/dwcr/metaschema/archive.rb, line 55
def load_nodes_from(xml)
  self.core = add_entity_from xml.css('core').first
  core.save
  xml.css('extension').each do |node|
    extn = add_entity_from node
    extn.add_attribute(name: 'coreid', index: index_from(node))
    add_extension(extn)
  end
  save
end

Private Instance Methods

add_entity_from(xml) click to toggle source

Creates a Entity instance from xml node (core or extension) adds Attribute instances for any field given adds ContentFile instances for any child node of files

# File lib/dwcr/metaschema/archive.rb, line 78
def add_entity_from(xml)
  entity = add_entity(values_from(xml, :term, :key_column))
  xml.css('field').each { |field| entity.add_attribute_from(field) }
  entity.add_files_from(xml, path: path)
  entity
end
before_create() click to toggle source

Sequel Model hook that creates a default name from the term if present

Calls superclass method
# File lib/dwcr/metaschema/archive.rb, line 70
def before_create
  self.name ||= path&.split('/')&.last
  super
end