Class: DwCR::Metaschema::Attribute
- Inherits:
-
Sequel::Model
- Object
- Sequel::Model
- DwCR::Metaschema::Attribute
- Includes:
- XMLParsable
- Defined in:
- lib/dwcr/metaschema/attribute.rb
Overview
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 the ContentFile instances associated with the Attribute instances’ parent Entity instance -
max_content_length
: the maximum string length of values in the corresponding column in the ContentFile instances associated with the Attribute instances’ parent Entity instance -
#entity: the Entity instance the Attribute instance belongs to
Instance Method Summary collapse
-
#baseterm ⇒ Object
Returns the last component of the term will return the full term is the term is not unambiguous.
-
#column_name ⇒ Object
Returns a symbol for the
name
that is the name of the column in the DarwinCoreArchive schema. -
#foreign_key? ⇒ Boolean
Reurns
true
if the field node is the foreign key in the core or an extension node in the DwCA schema,false
otherwise. -
#length ⇒ Object
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 themax_content_length
ornil
if neither is set. -
#to_table_column ⇒ Object
Returns an array that can be splatted as arguments into the Sequel::Schema::CreatTableGenerator#column method:
[name, type, options]
.
Methods included from XMLParsable
#default_from, #files_from, #index_from, #is_core_from, #key_column_from, load_meta, #method, #term_from, #update_from, validate_meta, #values_from
Instance Method Details
#baseterm ⇒ Object
Returns the last component of the term will return the full term is the term is not unambiguous
32 33 34 |
# File 'lib/dwcr/metaschema/attribute.rb', line 32 def baseterm unambiguous ? term&.split('/')&.last : term end |
#column_name ⇒ Object
Returns a symbol for the name
that is the name of the column in the DarwinCoreArchive schema
38 39 40 |
# File 'lib/dwcr/metaschema/attribute.rb', line 38 def column_name name.to_sym end |
#foreign_key? ⇒ Boolean
Reurns true
if the field node is the foreign key in the core or an extension node in the DwCA schema, false
otherwise
44 45 46 |
# File 'lib/dwcr/metaschema/attribute.rb', line 44 def foreign_key? index == entity.key_column && !entity.is_core end |
#length ⇒ Object
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
52 53 54 |
# File 'lib/dwcr/metaschema/attribute.rb', line 52 def length [default&.length, max_content_length].compact.max end |
#to_table_column ⇒ Object
Returns an array that can be splatted as arguments into the Sequel::Schema::CreatTableGenerator#column method: [name, type, options]
59 60 61 62 |
# File 'lib/dwcr/metaschema/attribute.rb', line 59 def to_table_column col_type = type ? type.to_sym : :string [column_name, col_type, { index: , default: default }] end |