Module: Shared::IsDwcOccurrence

Extended by:
ActiveSupport::Concern
Included in:
AssertedDistribution, CollectionObject
Defined in:
app/models/concerns/shared/is_dwc_occurrence.rb

Overview

Shared code for data classes that can be serialized as DwcOccurrence records

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#dwc_occurrence_attribute_valuesArray

Returns an array of the values presently computed for this occurrence

Returns:

  • (Array)

    an array of the values presently computed for this occurrence



57
58
59
# File 'app/models/concerns/shared/is_dwc_occurrence.rb', line 57

def dwc_occurrence_attribute_values
  [id, dwc_occurrence.id] + self.class.dwc_attribute_vector[2..-1].collect{|a| a.name}.collect{|f| dwc_occurrence.send(f) }
end

#dwc_occurrence_attributesObject



44
45
46
47
48
49
50
51
52
53
# File 'app/models/concerns/shared/is_dwc_occurrence.rb', line 44

def dwc_occurrence_attributes
  a = {}
  self.class::DWC_OCCURRENCE_MAP.each do |k,v|
    a[k] = send(v)
  end
  a[:project_id] = project_id
  a[:created_by_id] = created_by_id
  a[:updated_by_id] = updated_by_id
  a
end

#get_dwc_occurrenceDwcOccurrence

Returns does not rebuild if exists

Returns:



63
64
65
66
67
68
69
# File 'app/models/concerns/shared/is_dwc_occurrence.rb', line 63

def get_dwc_occurrence
  if dwc_occurrence_persisted?
    dwc_occurrence
  else
    set_dwc_occurrence
  end
end

#set_dwc_occurrenceDwcOccurrence

TODO: !! Currently uses updater_id of this record, need to change that to be user-definable

Returns:



35
36
37
38
39
40
41
42
# File 'app/models/concerns/shared/is_dwc_occurrence.rb', line 35

def set_dwc_occurrence
  if dwc_occurrence_persisted?
    dwc_occurrence.update(dwc_occurrence_attributes)
  else
    create_dwc_occurrence!(dwc_occurrence_attributes)
  end
  dwc_occurrence
end