Module: DynamicModelQueryable::DynamicModelClassQueryable

Defined in:
lib/dwcr/dynamic_model_queryable.rb

Overview

DynamicModelClassQueryable contains class methods for dynamic DwCR models.

Instance Method Summary collapse

Instance Method Details

#attribute_for(column_name) ⇒ Object

Returns the Metaschema::Attribute for a column_name (the header of the column, can be passed as Symbol or String).



9
10
11
# File 'lib/dwcr/dynamic_model_queryable.rb', line 9

def attribute_for(column_name)
  entity.attributes_dataset.first(name: column_name.to_s)
end

#entityObject

Returns the Metschema::Entity the class belongs to.



14
15
16
# File 'lib/dwcr/dynamic_model_queryable.rb', line 14

def entity
  @entity
end

#template(keys = :term) ⇒ Object

Returns a nested array of all terms in the order values will be returned by #to_a. Each item in the nested array will be an array with the entity term at index 0 and the attribute term at index 1.



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/dwcr/dynamic_model_queryable.rb', line 21

def template(keys = :term)
  tmpl = columns.map do |column|
    next unless attribute = attribute_for(column)
    [attribute.send(keys), entity.send(keys)]
  end.compact
  return tmpl.compact unless entity.is_core
  entity.extensions.each do |xtn|
    tmpl << xtn.model_get.template(keys)
  end
  tmpl
end

#termObject

Returns the full DwC class term (a uri), including namespace.



34
35
36
# File 'lib/dwcr/dynamic_model_queryable.rb', line 34

def term
  entity.term
end