Class: CharacterState
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- CharacterState
- Includes:
- Housekeeping, Shared::AlternateValues, Shared::Citations, Shared::Confidences, Shared::DataAttributes, Shared::Depictions, Shared::Documentation, Shared::Identifiers, Shared::IsData, Shared::Notes, Shared::Tags, SoftValidation
- Defined in:
- app/models/character_state.rb
Overview
A qualitative state, as traditionally used in Phylogenetic characters and descriptive taxonomy.
@!attribute name
@return [String]
the full name of the character state, like "blue"
@!attribute label
@return [String]
the label presented in the matrix, like "0", or "1"
Constant Summary collapse
- ALTERNATE_VALUES_FOR =
[:name, :label, :description_name, :key_name].freeze
Constants included from SoftValidation
SoftValidation::ANCESTORS_WITH_SOFT_VALIDATIONS
Class Method Summary collapse
Instance Method Summary collapse
- #dependent_destroy_error_message ⇒ Object protected
- #descriptor_kind ⇒ Object protected
- #is_gap? ⇒ Boolean
-
#target_name(target, language_id) ⇒ String
Name of the character_state in a particular language.
Methods included from SoftValidation
#clear_soft_validations, #fix_for, #fix_soft_validations, #soft_fixed?, #soft_valid?, #soft_validate, #soft_validated?, #soft_validations, #soft_validators
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::AlternateValues
#all_values_for, #alternate_valued?
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 Shared::Documentation
#document_array=, #documented?, #reject_documentation, #reject_documents
Methods included from Shared::Confidences
Methods included from Shared::Tags
#reject_tags, #tag_with, #tagged?, #tagged_with?
Methods included from Shared::Identifiers
#dwc_occurrence_id, #identified?, #next_by_identifier, #previous_by_identifier, #reject_identifiers, #uri, #uuid
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 Housekeeping
#has_polymorphic_relationship?
Methods inherited from ApplicationRecord
Class Method Details
.find_for_autocomplete(params) ⇒ Object
42 43 44 |
# File 'app/models/character_state.rb', line 42 def self.find_for_autocomplete(params) where('name ILIKE ?', "%#{params[:term]}%") end |
Instance Method Details
#dependent_destroy_error_message ⇒ Object (protected)
81 82 83 |
# File 'app/models/character_state.rb', line 81 def "Cannot delete this #{self.class.name} because it has associated #{dependent_models.class.name} records." end |
#descriptor_kind ⇒ Object (protected)
85 86 87 |
# File 'app/models/character_state.rb', line 85 def descriptor_kind errors.add(:descriptor, 'must be Descriptor::Qualitative') if descriptor && descriptor.type != 'Descriptor::Qualitative' end |
#is_gap? ⇒ Boolean
46 47 48 |
# File 'app/models/character_state.rb', line 46 def is_gap? label == '-' && name.downcase == 'gap' end |
#target_name(target, language_id) ⇒ String
Returns name of the character_state in a particular language.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/models/character_state.rb', line 53 def target_name(target, language_id) n = self.name a = nil case target when :key n = self.key_name.nil? ? n : self.key_name when :description n = self.description_name.nil? ? n : self.description_name end unless language_id.nil? case target when :key a = AlternateValue::Translation. where(alternate_value_object: self, language_id: language_id). where("(alternate_values.alternate_value_object_attribute = 'key_name' OR alternate_values.alternate_value_object_attribute = 'name')"). order(:alternate_value_object_attribute).pluck(:value).first when :description a = AlternateValue::Translation. where(alternate_value_object: self, language_id: language_id). where("(alternate_values.alternate_value_object_attribute = 'description_name' OR alternate_values.alternate_value_object_attribute = 'name')"). order(:alternate_value_object_attribute).pluck(:value).first end end return a.nil? ? n : a end |