class DwCR::Metaschema::Attribute

This class represents field nodes in the DarwinCoreArchive that correspond to columns in table sof the DwCA schema and where applicable the ContentFile instances

Public Instance Methods

baseterm() click to toggle source

Returns the last component of the term will return the full term is the term is not unambiguous

# File lib/dwcr/metaschema/attribute.rb, line 32
def baseterm
  unambiguous ? term&.split('/')&.last : term
end
column_name() click to toggle source

Returns a symbol for the name that is the name of the column in the DarwinCoreArchive schema

# File lib/dwcr/metaschema/attribute.rb, line 38
def column_name
  name.to_sym
end
foreign_key?() click to toggle source

Reurns true if the field node is the foreign key in the core or an extension node in the DwCA schema, false otherwise

# File lib/dwcr/metaschema/attribute.rb, line 44
def foreign_key?
  index == entity.key_column && !entity.is_core
end
length() click to toggle source

Returns the maximum length for values in the corresponding column in the DwCA schema the returned value is the greater of either the length of the default or the max_content_length or nil if neither is set

# File lib/dwcr/metaschema/attribute.rb, line 52
def length
  [default&.length, max_content_length].compact.max
end
to_table_column() click to toggle source

Returns an array that can be splatted as arguments into the Sequel::Schema::CreatTableGenerator#column method: [name, type, options]

# File lib/dwcr/metaschema/attribute.rb, line 59
def to_table_column
  col_type = type ? type.to_sym : :string
  [column_name, col_type, { index: index_options, default: default }]
end

Private Instance Methods

index_options() click to toggle source

Returns the index options for the Sequel database column by default DwCR does not persist the foreign key field of any extension nodes in the DwCA schema (as that relation is re-established through associations) using proper SQL foreign keys therefore the below else clause will never be reached in DwCR files generated from an existing DarwinCoreArchive

# File lib/dwcr/metaschema/attribute.rb, line 74
def index_options
  return false unless index && index == entity.key_column
  if entity.is_core
    { unique: true }
  else
    true
  end
end