Class: AssertedDistribution
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- AssertedDistribution
- Includes:
- DwcExtensions, Housekeeping, Shared::Citations, Shared::Confidences, Shared::DataAttributes, Shared::Identifiers, Shared::IsData, Shared::IsDwcOccurrence, Shared::Notes, Shared::OriginRelationship, Shared::Tags, Shared::Taxonomy, SoftValidation
- Defined in:
- app/models/asserted_distribution.rb
Overview
An AssertedDistribution is the source-backed assertion that a taxon (OTU) is present in some *spatial area*. It requires a Citation indicating where/who made the assertion. In TaxonWorks the areas are drawn from GeographicAreas, which essentially represent a gazeteer of 3 levels of subdivision (e.g. country, state, county).
AssertedDistributions can be asserts that the source indicates that a taxon is NOT present in an area. This is a “positive negative” in , i.e. the Source can be thought of recording evidence that a taxon is not present. TaxonWorks does not differentiate between types of negative evidence.
Defined Under Namespace
Modules: DwcExtensions
Constant Summary
Constants included from DwcExtensions
DwcExtensions::DWC_OCCURRENCE_MAP
Constants included from Shared::IsDwcOccurrence
Shared::IsDwcOccurrence::DWC_DELIMITER, Shared::IsDwcOccurrence::VIEW_EXCLUSIONS
Constants included from SoftValidation
SoftValidation::ANCESTORS_WITH_SOFT_VALIDATIONS
Instance Attribute Summary collapse
-
#geographic_area_id ⇒ Integer
the geographic area ID.
-
#geographic_names ⇒ Object
getter for attr :geographic_names.
-
#is_absent ⇒ Boolean
A positive negative, when true then there exists an assertion that the taxon is not present in the spatial area.
-
#otu_id ⇒ Integer
the OTU ID.
-
#project_id ⇒ Integer
the project ID.
Class Method Summary collapse
-
.stub(defaults: {}) ⇒ AssertedDistribution
Used to also stub an #origin_citation, as required.
-
.stub_new(options = {}) ⇒ Array
protected
An array of AssertedDistributions.
Instance Method Summary collapse
- #geographic_item ⇒ Object
- #has_shape? ⇒ Boolean
- #new_records_include_citation ⇒ Boolean protected
- #new_records_include_otu ⇒ Nil protected
-
#requires_citation? ⇒ True
See citable.rb.
- #sv_conflicting_geographic_area ⇒ Boolean protected
-
#to_geo_json_feature ⇒ Hash
rubocop:disable Style/StringHashKeys TODO: DRY with helper methods.
Methods included from DwcExtensions
#dwc_associated_references, #dwc_country, #dwc_county, #dwc_family, #dwc_genus, #dwc_infraspecific_epithet, #dwc_kingdom, #dwc_occurrence_status, #dwc_scientific_name, #dwc_specific_epithet, #dwc_state_province, #dwc_taxon_name_authorship, #dwc_taxon_rank
Methods included from Shared::IsDwcOccurrence
#dwc_occurrence_attribute_values, #dwc_occurrence_attributes, #dwc_occurrence_id, #get_dwc_occurrence, #set_dwc_occurrence
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::Identifiers
#dwc_occurrence_id, #identified?, #next_by_identifier, #previous_by_identifier, #reject_identifiers
Methods included from Shared::OriginRelationship
#new_objects, #old_objects, #reject_origin_relationships, #set_origin
Methods included from Shared::Confidences
Methods included from Shared::Citations
#cited?, #mark_citations_for_destruction, #nomenclature_date, #origin_citation_source_id, #reject_citations, #sources_by_topic_id
Methods included from Shared::DataAttributes
#import_attributes, #internal_attributes, #keyword_value_hash, #reject_data_attributes
Methods included from Shared::Tags
#reject_tags, #tag_with, #tagged?, #tagged_with?
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::Notes
#concatenated_notes_string, #reject_notes
Methods included from Housekeeping
#has_polymorphic_relationship?
Methods inherited from ApplicationRecord
Instance Attribute Details
#geographic_area_id ⇒ Integer
the geographic area ID
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'app/models/asserted_distribution.rb', line 22 class AssertedDistribution < ApplicationRecord include Housekeeping include Shared::Notes include SoftValidation include Shared::Tags include Shared::DataAttributes # why? include Shared::Citations include Shared::Confidences include Shared::OriginRelationship include Shared::Identifiers include Shared::IsData include Shared::Taxonomy # at present must be before IsDwcOccurence include Shared::IsDwcOccurrence include AssertedDistribution::DwcExtensions originates_from 'Specimen', 'Lot' # @return [Hash] # of known country/state/county values attr_accessor :geographic_names belongs_to :otu, inverse_of: :asserted_distributions has_one :taxon_name, through: :otu belongs_to :geographic_area, inverse_of: :asserted_distributions has_one :geographic_item, through: :geographic_area, source: :default_geographic_item has_many :geographic_items, through: :geographic_area validates_presence_of :geographic_area_id, message: 'geographic area is not selected' # Might not be able to do these for nested attributes validates :geographic_area, presence: true validates :otu, presence: true validates_uniqueness_of :geographic_area_id, scope: [:project_id, :otu_id, :is_absent], message: 'this geographic_area, OTU and present/absent combination already exists' validate :new_records_include_citation # TODO: deprecate scopes referencing single wheres scope :with_otu_id, -> (otu_id) { where(otu_id: otu_id) } scope :with_is_absent, -> { where('is_absent = true') } scope :with_geographic_area_array, -> (geographic_area_array) { where('geographic_area_id IN (?)', geographic_area_array) } scope :without_is_absent, -> { where('is_absent = false OR is_absent is Null') } accepts_nested_attributes_for :otu, allow_destroy: false, reject_if: proc { |attributes| attributes['name'].blank? && attributes['taxon_name_id'].blank? } soft_validate(:sv_conflicting_geographic_area, set: :conflicting_geographic_area, name: 'conflicting geographic area', description: 'conflicting geographic area') # getter for attr :geographic_names def geographic_names return @geographic_names if !@geographic_names.nil? @geographic_names ||= geographic_area.geographic_name_classification.delete_if{|k,v| v.nil?} @geographic_names ||= {} end # @param [Hash] defaults # @return [AssertedDistribution] # used to also stub an #origin_citation, as required def self.stub(defaults: {}) a = AssertedDistribution.new( otu_id: defaults[:otu_id], origin_citation_attributes: {source_id: defaults[:source_id]}) a.origin_citation = Citation.new if defaults[:source_id].blank? a end # rubocop:disable Style/StringHashKeys # TODO: DRY with helper methods # @return [Hash] GeoJSON feature def to_geo_json_feature retval = { 'type' => 'Feature', 'geometry' => RGeo::GeoJSON.encode(self.geographic_area.geographic_items.first.geo_object), 'properties' => {'asserted_distribution' => {'id' => self.id}} } retval end # rubocop:enable Style/StringHashKeys # @return [True] # see citable.rb def requires_citation? true end def geographic_item geographic_area.default_geographic_item end def has_shape? geographic_area.geographic_items.any? end protected # @return [Boolean] def new_records_include_citation if new_record? && source.blank? && origin_citation.blank? && !citations.any? errors.add(:base, 'required citation is not provided') end end # @return [Nil] def new_records_include_otu end # @return [Boolean] def sv_conflicting_geographic_area unless geographic_area.nil? areas = [geographic_area.level0_id, geographic_area.level1_id, geographic_area.level2_id].compact if is_absent # this returns an array, not a single GA so test below is not right presence = AssertedDistribution .without_is_absent .with_geographic_area_array(areas) .where(otu_id: otu_id) soft_validations.add(:geographic_area_id, "Taxon is reported as present in #{presence.first.geographic_area.name}") unless presence.empty? else presence = AssertedDistribution .with_is_absent .where(otu_id: otu_id) .with_geographic_area_array(areas) soft_validations.add(:geographic_area_id, "Taxon is reported as missing in #{presence.first.geographic_area.name}") unless presence.empty? end end end # @param [Hash] options of e.g., {otu_id: 5, source_id: 5, geographic_areas: Array of {GeographicArea}} # @return [Array] an array of AssertedDistributions def self.stub_new( = {}) .symbolize_keys! result = [] [:geographic_areas].each do |ga| result.push( AssertedDistribution.new( otu_id: [:otu_id], geographic_area: ga, origin_citation_attributes: {source_id: [:source_id]}) ) end result end end |
#geographic_names ⇒ Object
getter for attr :geographic_names
42 43 44 |
# File 'app/models/asserted_distribution.rb', line 42 def geographic_names @geographic_names end |
#is_absent ⇒ Boolean
Returns a positive negative, when true then there exists an assertion that the taxon is not present in the spatial area.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'app/models/asserted_distribution.rb', line 22 class AssertedDistribution < ApplicationRecord include Housekeeping include Shared::Notes include SoftValidation include Shared::Tags include Shared::DataAttributes # why? include Shared::Citations include Shared::Confidences include Shared::OriginRelationship include Shared::Identifiers include Shared::IsData include Shared::Taxonomy # at present must be before IsDwcOccurence include Shared::IsDwcOccurrence include AssertedDistribution::DwcExtensions originates_from 'Specimen', 'Lot' # @return [Hash] # of known country/state/county values attr_accessor :geographic_names belongs_to :otu, inverse_of: :asserted_distributions has_one :taxon_name, through: :otu belongs_to :geographic_area, inverse_of: :asserted_distributions has_one :geographic_item, through: :geographic_area, source: :default_geographic_item has_many :geographic_items, through: :geographic_area validates_presence_of :geographic_area_id, message: 'geographic area is not selected' # Might not be able to do these for nested attributes validates :geographic_area, presence: true validates :otu, presence: true validates_uniqueness_of :geographic_area_id, scope: [:project_id, :otu_id, :is_absent], message: 'this geographic_area, OTU and present/absent combination already exists' validate :new_records_include_citation # TODO: deprecate scopes referencing single wheres scope :with_otu_id, -> (otu_id) { where(otu_id: otu_id) } scope :with_is_absent, -> { where('is_absent = true') } scope :with_geographic_area_array, -> (geographic_area_array) { where('geographic_area_id IN (?)', geographic_area_array) } scope :without_is_absent, -> { where('is_absent = false OR is_absent is Null') } accepts_nested_attributes_for :otu, allow_destroy: false, reject_if: proc { |attributes| attributes['name'].blank? && attributes['taxon_name_id'].blank? } soft_validate(:sv_conflicting_geographic_area, set: :conflicting_geographic_area, name: 'conflicting geographic area', description: 'conflicting geographic area') # getter for attr :geographic_names def geographic_names return @geographic_names if !@geographic_names.nil? @geographic_names ||= geographic_area.geographic_name_classification.delete_if{|k,v| v.nil?} @geographic_names ||= {} end # @param [Hash] defaults # @return [AssertedDistribution] # used to also stub an #origin_citation, as required def self.stub(defaults: {}) a = AssertedDistribution.new( otu_id: defaults[:otu_id], origin_citation_attributes: {source_id: defaults[:source_id]}) a.origin_citation = Citation.new if defaults[:source_id].blank? a end # rubocop:disable Style/StringHashKeys # TODO: DRY with helper methods # @return [Hash] GeoJSON feature def to_geo_json_feature retval = { 'type' => 'Feature', 'geometry' => RGeo::GeoJSON.encode(self.geographic_area.geographic_items.first.geo_object), 'properties' => {'asserted_distribution' => {'id' => self.id}} } retval end # rubocop:enable Style/StringHashKeys # @return [True] # see citable.rb def requires_citation? true end def geographic_item geographic_area.default_geographic_item end def has_shape? geographic_area.geographic_items.any? end protected # @return [Boolean] def new_records_include_citation if new_record? && source.blank? && origin_citation.blank? && !citations.any? errors.add(:base, 'required citation is not provided') end end # @return [Nil] def new_records_include_otu end # @return [Boolean] def sv_conflicting_geographic_area unless geographic_area.nil? areas = [geographic_area.level0_id, geographic_area.level1_id, geographic_area.level2_id].compact if is_absent # this returns an array, not a single GA so test below is not right presence = AssertedDistribution .without_is_absent .with_geographic_area_array(areas) .where(otu_id: otu_id) soft_validations.add(:geographic_area_id, "Taxon is reported as present in #{presence.first.geographic_area.name}") unless presence.empty? else presence = AssertedDistribution .with_is_absent .where(otu_id: otu_id) .with_geographic_area_array(areas) soft_validations.add(:geographic_area_id, "Taxon is reported as missing in #{presence.first.geographic_area.name}") unless presence.empty? end end end # @param [Hash] options of e.g., {otu_id: 5, source_id: 5, geographic_areas: Array of {GeographicArea}} # @return [Array] an array of AssertedDistributions def self.stub_new( = {}) .symbolize_keys! result = [] [:geographic_areas].each do |ga| result.push( AssertedDistribution.new( otu_id: [:otu_id], geographic_area: ga, origin_citation_attributes: {source_id: [:source_id]}) ) end result end end |
#otu_id ⇒ Integer
the OTU ID
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'app/models/asserted_distribution.rb', line 22 class AssertedDistribution < ApplicationRecord include Housekeeping include Shared::Notes include SoftValidation include Shared::Tags include Shared::DataAttributes # why? include Shared::Citations include Shared::Confidences include Shared::OriginRelationship include Shared::Identifiers include Shared::IsData include Shared::Taxonomy # at present must be before IsDwcOccurence include Shared::IsDwcOccurrence include AssertedDistribution::DwcExtensions originates_from 'Specimen', 'Lot' # @return [Hash] # of known country/state/county values attr_accessor :geographic_names belongs_to :otu, inverse_of: :asserted_distributions has_one :taxon_name, through: :otu belongs_to :geographic_area, inverse_of: :asserted_distributions has_one :geographic_item, through: :geographic_area, source: :default_geographic_item has_many :geographic_items, through: :geographic_area validates_presence_of :geographic_area_id, message: 'geographic area is not selected' # Might not be able to do these for nested attributes validates :geographic_area, presence: true validates :otu, presence: true validates_uniqueness_of :geographic_area_id, scope: [:project_id, :otu_id, :is_absent], message: 'this geographic_area, OTU and present/absent combination already exists' validate :new_records_include_citation # TODO: deprecate scopes referencing single wheres scope :with_otu_id, -> (otu_id) { where(otu_id: otu_id) } scope :with_is_absent, -> { where('is_absent = true') } scope :with_geographic_area_array, -> (geographic_area_array) { where('geographic_area_id IN (?)', geographic_area_array) } scope :without_is_absent, -> { where('is_absent = false OR is_absent is Null') } accepts_nested_attributes_for :otu, allow_destroy: false, reject_if: proc { |attributes| attributes['name'].blank? && attributes['taxon_name_id'].blank? } soft_validate(:sv_conflicting_geographic_area, set: :conflicting_geographic_area, name: 'conflicting geographic area', description: 'conflicting geographic area') # getter for attr :geographic_names def geographic_names return @geographic_names if !@geographic_names.nil? @geographic_names ||= geographic_area.geographic_name_classification.delete_if{|k,v| v.nil?} @geographic_names ||= {} end # @param [Hash] defaults # @return [AssertedDistribution] # used to also stub an #origin_citation, as required def self.stub(defaults: {}) a = AssertedDistribution.new( otu_id: defaults[:otu_id], origin_citation_attributes: {source_id: defaults[:source_id]}) a.origin_citation = Citation.new if defaults[:source_id].blank? a end # rubocop:disable Style/StringHashKeys # TODO: DRY with helper methods # @return [Hash] GeoJSON feature def to_geo_json_feature retval = { 'type' => 'Feature', 'geometry' => RGeo::GeoJSON.encode(self.geographic_area.geographic_items.first.geo_object), 'properties' => {'asserted_distribution' => {'id' => self.id}} } retval end # rubocop:enable Style/StringHashKeys # @return [True] # see citable.rb def requires_citation? true end def geographic_item geographic_area.default_geographic_item end def has_shape? geographic_area.geographic_items.any? end protected # @return [Boolean] def new_records_include_citation if new_record? && source.blank? && origin_citation.blank? && !citations.any? errors.add(:base, 'required citation is not provided') end end # @return [Nil] def new_records_include_otu end # @return [Boolean] def sv_conflicting_geographic_area unless geographic_area.nil? areas = [geographic_area.level0_id, geographic_area.level1_id, geographic_area.level2_id].compact if is_absent # this returns an array, not a single GA so test below is not right presence = AssertedDistribution .without_is_absent .with_geographic_area_array(areas) .where(otu_id: otu_id) soft_validations.add(:geographic_area_id, "Taxon is reported as present in #{presence.first.geographic_area.name}") unless presence.empty? else presence = AssertedDistribution .with_is_absent .where(otu_id: otu_id) .with_geographic_area_array(areas) soft_validations.add(:geographic_area_id, "Taxon is reported as missing in #{presence.first.geographic_area.name}") unless presence.empty? end end end # @param [Hash] options of e.g., {otu_id: 5, source_id: 5, geographic_areas: Array of {GeographicArea}} # @return [Array] an array of AssertedDistributions def self.stub_new( = {}) .symbolize_keys! result = [] [:geographic_areas].each do |ga| result.push( AssertedDistribution.new( otu_id: [:otu_id], geographic_area: ga, origin_citation_attributes: {source_id: [:source_id]}) ) end result end end |
#project_id ⇒ Integer
the project ID
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'app/models/asserted_distribution.rb', line 22 class AssertedDistribution < ApplicationRecord include Housekeeping include Shared::Notes include SoftValidation include Shared::Tags include Shared::DataAttributes # why? include Shared::Citations include Shared::Confidences include Shared::OriginRelationship include Shared::Identifiers include Shared::IsData include Shared::Taxonomy # at present must be before IsDwcOccurence include Shared::IsDwcOccurrence include AssertedDistribution::DwcExtensions originates_from 'Specimen', 'Lot' # @return [Hash] # of known country/state/county values attr_accessor :geographic_names belongs_to :otu, inverse_of: :asserted_distributions has_one :taxon_name, through: :otu belongs_to :geographic_area, inverse_of: :asserted_distributions has_one :geographic_item, through: :geographic_area, source: :default_geographic_item has_many :geographic_items, through: :geographic_area validates_presence_of :geographic_area_id, message: 'geographic area is not selected' # Might not be able to do these for nested attributes validates :geographic_area, presence: true validates :otu, presence: true validates_uniqueness_of :geographic_area_id, scope: [:project_id, :otu_id, :is_absent], message: 'this geographic_area, OTU and present/absent combination already exists' validate :new_records_include_citation # TODO: deprecate scopes referencing single wheres scope :with_otu_id, -> (otu_id) { where(otu_id: otu_id) } scope :with_is_absent, -> { where('is_absent = true') } scope :with_geographic_area_array, -> (geographic_area_array) { where('geographic_area_id IN (?)', geographic_area_array) } scope :without_is_absent, -> { where('is_absent = false OR is_absent is Null') } accepts_nested_attributes_for :otu, allow_destroy: false, reject_if: proc { |attributes| attributes['name'].blank? && attributes['taxon_name_id'].blank? } soft_validate(:sv_conflicting_geographic_area, set: :conflicting_geographic_area, name: 'conflicting geographic area', description: 'conflicting geographic area') # getter for attr :geographic_names def geographic_names return @geographic_names if !@geographic_names.nil? @geographic_names ||= geographic_area.geographic_name_classification.delete_if{|k,v| v.nil?} @geographic_names ||= {} end # @param [Hash] defaults # @return [AssertedDistribution] # used to also stub an #origin_citation, as required def self.stub(defaults: {}) a = AssertedDistribution.new( otu_id: defaults[:otu_id], origin_citation_attributes: {source_id: defaults[:source_id]}) a.origin_citation = Citation.new if defaults[:source_id].blank? a end # rubocop:disable Style/StringHashKeys # TODO: DRY with helper methods # @return [Hash] GeoJSON feature def to_geo_json_feature retval = { 'type' => 'Feature', 'geometry' => RGeo::GeoJSON.encode(self.geographic_area.geographic_items.first.geo_object), 'properties' => {'asserted_distribution' => {'id' => self.id}} } retval end # rubocop:enable Style/StringHashKeys # @return [True] # see citable.rb def requires_citation? true end def geographic_item geographic_area.default_geographic_item end def has_shape? geographic_area.geographic_items.any? end protected # @return [Boolean] def new_records_include_citation if new_record? && source.blank? && origin_citation.blank? && !citations.any? errors.add(:base, 'required citation is not provided') end end # @return [Nil] def new_records_include_otu end # @return [Boolean] def sv_conflicting_geographic_area unless geographic_area.nil? areas = [geographic_area.level0_id, geographic_area.level1_id, geographic_area.level2_id].compact if is_absent # this returns an array, not a single GA so test below is not right presence = AssertedDistribution .without_is_absent .with_geographic_area_array(areas) .where(otu_id: otu_id) soft_validations.add(:geographic_area_id, "Taxon is reported as present in #{presence.first.geographic_area.name}") unless presence.empty? else presence = AssertedDistribution .with_is_absent .where(otu_id: otu_id) .with_geographic_area_array(areas) soft_validations.add(:geographic_area_id, "Taxon is reported as missing in #{presence.first.geographic_area.name}") unless presence.empty? end end end # @param [Hash] options of e.g., {otu_id: 5, source_id: 5, geographic_areas: Array of {GeographicArea}} # @return [Array] an array of AssertedDistributions def self.stub_new( = {}) .symbolize_keys! result = [] [:geographic_areas].each do |ga| result.push( AssertedDistribution.new( otu_id: [:otu_id], geographic_area: ga, origin_citation_attributes: {source_id: [:source_id]}) ) end result end end |
Class Method Details
.stub(defaults: {}) ⇒ AssertedDistribution
Returns used to also stub an #origin_citation, as required.
84 85 86 87 88 89 90 |
# File 'app/models/asserted_distribution.rb', line 84 def self.stub(defaults: {}) a = AssertedDistribution.new( otu_id: defaults[:otu_id], origin_citation_attributes: {source_id: defaults[:source_id]}) a.origin_citation = Citation.new if defaults[:source_id].blank? a end |
.stub_new(options = {}) ⇒ Array (protected)
Returns an array of AssertedDistributions.
155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'app/models/asserted_distribution.rb', line 155 def self.stub_new( = {}) .symbolize_keys! result = [] [:geographic_areas].each do |ga| result.push( AssertedDistribution.new( otu_id: [:otu_id], geographic_area: ga, origin_citation_attributes: {source_id: [:source_id]}) ) end result end |
Instance Method Details
#geographic_item ⇒ Object
112 113 114 |
# File 'app/models/asserted_distribution.rb', line 112 def geographic_item geographic_area.default_geographic_item end |
#has_shape? ⇒ Boolean
116 117 118 |
# File 'app/models/asserted_distribution.rb', line 116 def has_shape? geographic_area.geographic_items.any? end |
#new_records_include_citation ⇒ Boolean (protected)
123 124 125 126 127 |
# File 'app/models/asserted_distribution.rb', line 123 def new_records_include_citation if new_record? && source.blank? && origin_citation.blank? && !citations.any? errors.add(:base, 'required citation is not provided') end end |
#new_records_include_otu ⇒ Nil (protected)
130 131 |
# File 'app/models/asserted_distribution.rb', line 130 def new_records_include_otu end |
#requires_citation? ⇒ True
Returns see citable.rb.
108 109 110 |
# File 'app/models/asserted_distribution.rb', line 108 def requires_citation? true end |
#sv_conflicting_geographic_area ⇒ Boolean (protected)
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'app/models/asserted_distribution.rb', line 134 def sv_conflicting_geographic_area unless geographic_area.nil? areas = [geographic_area.level0_id, geographic_area.level1_id, geographic_area.level2_id].compact if is_absent # this returns an array, not a single GA so test below is not right presence = AssertedDistribution .without_is_absent .with_geographic_area_array(areas) .where(otu_id: otu_id) soft_validations.add(:geographic_area_id, "Taxon is reported as present in #{presence.first.geographic_area.name}") unless presence.empty? else presence = AssertedDistribution .with_is_absent .where(otu_id: otu_id) .with_geographic_area_array(areas) soft_validations.add(:geographic_area_id, "Taxon is reported as missing in #{presence.first.geographic_area.name}") unless presence.empty? end end end |
#to_geo_json_feature ⇒ Hash
rubocop:disable Style/StringHashKeys TODO: DRY with helper methods
95 96 97 98 99 100 101 102 |
# File 'app/models/asserted_distribution.rb', line 95 def to_geo_json_feature retval = { 'type' => 'Feature', 'geometry' => RGeo::GeoJSON.encode(self.geographic_area.geographic_items.first.geo_object), 'properties' => {'asserted_distribution' => {'id' => self.id}} } retval end |