Class: Observation::Continuous

Inherits:
Observation show all
Defined in:
app/models/observation/continuous.rb

Instance Attribute Summary

Attributes inherited from Observation

#observation_object_global_id

Instance Method Summary collapse

Methods inherited from Observation

by_descriptors_and_rows, #continuous?, #convert_observation_object_global_id, copy, destroy_row, human_name, in_observation_matrix, object_scope, #observation_object, #otu_or_collection_object_set, #presence_absence?, #qualitative?, #set_observation_object_id, #set_type_from_descriptor, #type_matches_descriptor

Methods included from Shared::IsData

#errors_excepting, #full_error_messages_excepting, #identical, #is_community?, #is_destroyable?, #is_editable?, #is_in_use?, #is_in_users_projects?, #metamorphosize, #similar

Methods included from Shared::Confidences

#reject_confidences

Methods included from Shared::Tags

#reject_tags, #tag_with, #tagged?, #tagged_with?

Methods included from Shared::Notes

#concatenated_notes_string, #reject_notes

Methods included from Shared::Depictions

#has_depictions?, #image_array=, #reject_depictions, #reject_images

Methods included from Shared::Identifiers

#identified?, #next_by_identifier, #previous_by_identifier, #reject_identifiers

Methods included from Shared::DataAttributes

#import_attributes, #internal_attributes, #keyword_value_hash, #reject_data_attributes

Methods included from Shared::Citations

#cited?, #mark_citations_for_destruction, #nomenclature_date, #origin_citation_source_id, #reject_citations, #requires_citation?, #sources_by_topic_id

Methods included from Housekeeping

#has_polymorphic_relationship?

Methods inherited from ApplicationRecord

transaction_with_retry

Instance Method Details

#+(observation) ⇒ Object

Use Ruby Units to add



17
18
19
20
# File 'app/models/observation/continuous.rb', line 17

def +(observation)
  a = unit + observation.unit
  continuous_unit && descriptor.default_unit ? a.convert_to(descriptor.default_unit) : a
end

#-(observation) ⇒ Object



22
23
24
25
# File 'app/models/observation/continuous.rb', line 22

def -(observation)
  a = unit - observation.unit
  continuous_unit && descriptor.default_unit ? a.convert_to(descriptor.default_unit) : a
end

#converted_valueFloat

Return the value converted to the default of the descriptor If provided

Returns:

  • (Float)

    return the value converted to the default of the descriptor If provided



29
30
31
32
33
34
35
36
37
# File 'app/models/observation/continuous.rb', line 29

def converted_value
  if continuous_unit && descriptor.default_unit
    unit.convert_to(descriptor.default_unit).scalar.to_f # TODO: experiment with this
  elsif continuous_unit
    unit.scalar
  else
    continuous_value
  end
end

#unitUnit

Returns and instance of ruby-unit.

Returns:

  • (Unit)

    and instance of ruby-unit



12
13
14
# File 'app/models/observation/continuous.rb', line 12

def unit
  ::RubyUnits::Unit.new(continuous_value.to_s + ' ' + continuous_unit)
end

#units_compatibleObject (protected)



41
42
43
44
45
46
# File 'app/models/observation/continuous.rb', line 41

def units_compatible
  if descriptor && descriptor.default_unit && !continuous_unit.blank?
    # The =~ operator checks for convertability here.
    errors.add(:continuous_unit, 'units incompatible with descriptor default') unless unit =~ descriptor.unit
  end
end