Class: Specify::Model::CollectionObject

Inherits:
Object
  • Object
show all
Includes:
Createable, Updateable
Defined in:
lib/specify/models/collection_object.rb

Overview

CollectionObjects represent the organisms or artifeacts collected, but not the physical items stored in a collection (see Specify::Model::Preparation).

A CollectionObject belongs to Specify::Model::Collection and can have one or many #preparations (instances of Specify::Model::Preparation).

A CollectionObject belongs to a #collecting_event (an instance of Specify::Model::CollectingEvent), that holds information about when, where, how, and by whom it was collected.

A CollectionObject can have one or many #determinations (instances of Specify::Model::Determination), which represent opinions on what Specify::Model::Taxon the CollectionObject represents.

Instance Method Summary collapse

Methods included from Updateable

#before_update

Instance Method Details

#auto_numberObject

Returns the #catalog_number of self if it has one. If not, returns the next available catalog number in the Specify::Model::AutoNumberingScheme in the Specify::Model::Collection self belongs to.



50
51
52
# File 'lib/specify/models/collection_object.rb', line 50

def auto_number
  catalog_number || collection.auto_numbering_scheme.increment
end

#before_createObject

Sequel hook that assigns a newly created records to a Specify::Model::Collection (the collection is referenced twice; through #collection and #collection_member; the #collection will be automatically set if the records is created through the Specify::Model::Collecion#add_collection_object association method; the hook will set the other reference).

Assigns the next available #catalog_number in the collection.

Sets the CatalogedDate attribute and assigns a Specify::Model::Agent as the #cataloger.

Assigns a GUID.

If CollectionObjects in #collection can not share colecting events (there is one Specify::Model::CollectingEvent for every CollectionObject), this will create a new, empty, Specify::Model::CollectingEvent for the record.



72
73
74
75
76
77
78
79
80
# File 'lib/specify/models/collection_object.rb', line 72

def before_create
  self.collection_member = collection
  self[:CatalogNumber] = auto_number
  self[:CatalogedDate] = Date.today
  self[:CatalogedDatePrecision] = 1
  self[:GUID] = SecureRandom.uuid
  self.collecting_event = embed_collecting_event
  super
end

#catalog_numberObject

Returns a String that is the catalog number of self.



83
84
85
# File 'lib/specify/models/collection_object.rb', line 83

def catalog_number
  self[:CatalogNumber]
end

#cataloged_dateObject

Returns a Date that is the date self was cataloged (typically when it was registered in the database).



89
90
91
# File 'lib/specify/models/collection_object.rb', line 89

def cataloged_date
  self[:CatalogedDate]
end

#embed_collecting_eventObject

If CollectionObjects in #collection can not share colecting events (there is one Specify::Model::CollectingEvent for every CollectionObject), this will create a new, empty, Specify::Model::CollectingEvent for the record.



97
98
99
100
# File 'lib/specify/models/collection_object.rb', line 97

def embed_collecting_event
  return unless collection.embedded_collecting_event?
  CollectingEvent.create discipline: collection.discipline
end

#geo_locate(vals) ⇒ Object

Updates the associated Specify::Model::CollectingEvent with vals (a Hash).



104
105
106
107
# File 'lib/specify/models/collection_object.rb', line 104

def geo_locate(vals)
  collecting_event.update(vals)
  collecting_event.save
end

#identify(vals) ⇒ Object

Creates a new Specify::Model::Determination for self with vals (a Hash).



111
112
113
114
# File 'lib/specify/models/collection_object.rb', line 111

def identify(vals)
  add_determination vals
  self.save
end

#inspectObject

Creates a string representation of self.



117
118
119
# File 'lib/specify/models/collection_object.rb', line 117

def inspect
  to_s
end

#to_sObject

Creates a string representation of self.



122
123
124
# File 'lib/specify/models/collection_object.rb', line 122

def to_s
  "#{catalog_number} cataloged by #{cataloger}, #{cataloged_date}"
end