Class: Observation::Continuous
- Inherits:
-
Observation
- Object
- ActiveRecord::Base
- ApplicationRecord
- Observation
- Observation::Continuous
- Defined in:
- app/models/observation/continuous.rb
Instance Attribute Summary
Attributes inherited from Observation
#cached, #cached_column_label, #cached_row_label, #character_state_id, #continuous_unit, #continuous_value, #day_made, #descriptions, #descriptor_id, #frequency, #month_made, #observation_object_global_id, #observation_object_id, #observation_object_type, #presence, #project_id, #sample_max, #sample_mean, #sample_median, #sample_min, #sample_n, #sample_standard_deviation, #sample_standard_error, #sample_standard_units, #time_made, #type, #year_made
Instance Method Summary collapse
-
#+(observation) ⇒ Object
Use Ruby Units to add.
- #-(observation) ⇒ Object
-
#converted_value ⇒ Float
Return the value converted to the default of the descriptor If provided.
-
#unit ⇒ Unit
And instance of ruby-unit.
- #units_compatible ⇒ Object protected
Methods inherited from Observation
by_matrix_and_position, by_observation_matrix_row, code_column, #continuous?, copy, destroy_column, destroy_row, human_name, in_observation_matrix, object_scope, #presence_absence?, #qualitative?, #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::ProtocolRelationships
#protocolled?, #reject_protocols
Methods included from Shared::Confidences
Methods included from Shared::Depictions
#has_depictions?, #image_array=, #reject_depictions, #reject_images
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::Identifiers
#dwc_occurrence_id, #identified?, #next_by_identifier, #previous_by_identifier, #reject_identifiers, #uri, #uuid
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
Instance Method Details
#+(observation) ⇒ Object
Use Ruby Units to add
19 20 21 22 |
# File 'app/models/observation/continuous.rb', line 19 def +(observation) a = unit + observation.unit continuous_unit && descriptor.default_unit ? a.convert_to(descriptor.default_unit) : a end |
#-(observation) ⇒ Object
24 25 26 27 |
# File 'app/models/observation/continuous.rb', line 24 def -(observation) a = unit - observation.unit continuous_unit && descriptor.default_unit ? a.convert_to(descriptor.default_unit) : a end |
#converted_value ⇒ Float
Return the value converted to the default of the descriptor If provided
31 32 33 34 35 36 37 38 39 |
# File 'app/models/observation/continuous.rb', line 31 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 |
#unit ⇒ Unit
Returns and instance of ruby-unit.
14 15 16 |
# File 'app/models/observation/continuous.rb', line 14 def unit ::RubyUnits::Unit.new([continuous_value.to_s, continuous_unit].compact.join(' ')) end |
#units_compatible ⇒ Object (protected)
43 44 45 46 47 48 |
# File 'app/models/observation/continuous.rb', line 43 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 |