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
-
type
: the column type of the node default: 'string' -
name
: the name for the node default: term without namespace in underscore (snake case) form -
term
: the full term (a uri), including namespace for the node see rs.tdwg.org/dwc/terms/index.htm -
default
: the default vale for columns in the DwCA schema table -
index
: the column index in theContentFile
instances associated with theAttribute
instances' parentEntity
instance -
max_content_length
: the maximum string length of values in the corresponding column in theContentFile
instances associated with theAttribute
instances' parentEntity
instance -
#entity: the
Entity
instance theAttribute
instance belongs to
Public Instance Methods
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
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
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
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
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
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