Class: TaxonDetermination

Inherits:
ApplicationRecord show all
Includes:
Housekeeping, Shared::Citations, Shared::Confidences, Shared::DataAttributes, Shared::HasRoles, Shared::IsData, Shared::Notes
Defined in:
app/models/taxon_determination.rb

Overview

A Taxon determination is an assertion that a collection object belongs to a taxonomic concept.

If you wish to capture verbatim determinations then they should be added to CollectionObject#buffered_determinations, i.e. TaxonDeterminations are fully “normalized”.

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from Housekeeping

#has_polymorphic_relationship?

Methods included from ActiverecordUtilities

#trim_attributes

Instance Attribute Details

- (Integer) biological_collection_object_id

BiologicalCollectionObject, the object being determined

Returns:

  • (Integer)


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
# File 'app/models/taxon_determination.rb', line 36

class TaxonDetermination < ApplicationRecord
  acts_as_list scope: [:biological_collection_object_id]

  include Housekeeping
  include Shared::Citations
  include Shared::DataAttributes
  include Shared::Notes
  include Shared::Confidences
  include Shared::HasRoles
  include Shared::IsData

  belongs_to :otu, inverse_of: :taxon_determinations
  belongs_to :biological_collection_object, class_name: 'CollectionObject', inverse_of: :taxon_determinations, foreign_key: :biological_collection_object_id

  has_many :determiner_roles, class_name: 'Determiner', as: :role_object
  has_many :determiners, through: :determiner_roles, source: :person

  # validates :biological_collection_object, presence: true
  # validates :otu, presence: true
  # # TODO - probably bad, and preventing nested determinations, should just use DB validation

  accepts_nested_attributes_for :determiners
  accepts_nested_attributes_for :determiner_roles, allow_destroy: true

  # accepts_nested_attributes_for :biological_collection_object
  accepts_nested_attributes_for :otu, allow_destroy: false, reject_if: :reject_otu

  validates :year_made, date_year: { min_year: 1757, max_year: Time.now.year }
  validates :month_made, date_month: true
  validates :day_made, date_day: {year_sym: :year_made, month_sym: :month_made}, unless: -> {year_made.nil? || month_made.nil?}

  before_save :set_made_fields_if_not_provided
  after_create :sort_to_top

  # @return [Object]
  def sort_to_top
    reload
    self.move_to_top
  end

  # @return [String]
  def date
    [year_made, month_made, day_made].compact.join('-')
  end

  # @return [Time]
  def sort_date
    Utilities::Dates.nomenclature_date(day_made, month_made, year_made)
  end

  # @param [ActionController::Parameters] params
  # @return [Scope]
  def self.find_for_autocomplete(params)
    where(id: params[:term]).with_project_id(params[:project_id])
  end

  protected

  # @param [Hash] attributed
  # @return [Boolean]
  def reject_otu(attributed)
    attributed['name'].blank? && attributed['taxon_name_id'].blank?
  end

  # @return [Boolean] always true
  def set_made_fields_if_not_provided
    if self.year_made.blank? && self.month_made.blank? && self.day_made.blank?
      self.year_made  = Time.now.year
      self.month_made = Time.now.month
      self.day_made   = Time.now.day
    end
    true
  end

end

- (Integer) day_made

the day of the month the determination was made

Returns:

  • (Integer)


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
# File 'app/models/taxon_determination.rb', line 36

class TaxonDetermination < ApplicationRecord
  acts_as_list scope: [:biological_collection_object_id]

  include Housekeeping
  include Shared::Citations
  include Shared::DataAttributes
  include Shared::Notes
  include Shared::Confidences
  include Shared::HasRoles
  include Shared::IsData

  belongs_to :otu, inverse_of: :taxon_determinations
  belongs_to :biological_collection_object, class_name: 'CollectionObject', inverse_of: :taxon_determinations, foreign_key: :biological_collection_object_id

  has_many :determiner_roles, class_name: 'Determiner', as: :role_object
  has_many :determiners, through: :determiner_roles, source: :person

  # validates :biological_collection_object, presence: true
  # validates :otu, presence: true
  # # TODO - probably bad, and preventing nested determinations, should just use DB validation

  accepts_nested_attributes_for :determiners
  accepts_nested_attributes_for :determiner_roles, allow_destroy: true

  # accepts_nested_attributes_for :biological_collection_object
  accepts_nested_attributes_for :otu, allow_destroy: false, reject_if: :reject_otu

  validates :year_made, date_year: { min_year: 1757, max_year: Time.now.year }
  validates :month_made, date_month: true
  validates :day_made, date_day: {year_sym: :year_made, month_sym: :month_made}, unless: -> {year_made.nil? || month_made.nil?}

  before_save :set_made_fields_if_not_provided
  after_create :sort_to_top

  # @return [Object]
  def sort_to_top
    reload
    self.move_to_top
  end

  # @return [String]
  def date
    [year_made, month_made, day_made].compact.join('-')
  end

  # @return [Time]
  def sort_date
    Utilities::Dates.nomenclature_date(day_made, month_made, year_made)
  end

  # @param [ActionController::Parameters] params
  # @return [Scope]
  def self.find_for_autocomplete(params)
    where(id: params[:term]).with_project_id(params[:project_id])
  end

  protected

  # @param [Hash] attributed
  # @return [Boolean]
  def reject_otu(attributed)
    attributed['name'].blank? && attributed['taxon_name_id'].blank?
  end

  # @return [Boolean] always true
  def set_made_fields_if_not_provided
    if self.year_made.blank? && self.month_made.blank? && self.day_made.blank?
      self.year_made  = Time.now.year
      self.month_made = Time.now.month
      self.day_made   = Time.now.day
    end
    true
  end

end

- (Integer) month_made

Returns the month the determination was made

Returns:

  • (Integer)

    the month the determination was made



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
# File 'app/models/taxon_determination.rb', line 36

class TaxonDetermination < ApplicationRecord
  acts_as_list scope: [:biological_collection_object_id]

  include Housekeeping
  include Shared::Citations
  include Shared::DataAttributes
  include Shared::Notes
  include Shared::Confidences
  include Shared::HasRoles
  include Shared::IsData

  belongs_to :otu, inverse_of: :taxon_determinations
  belongs_to :biological_collection_object, class_name: 'CollectionObject', inverse_of: :taxon_determinations, foreign_key: :biological_collection_object_id

  has_many :determiner_roles, class_name: 'Determiner', as: :role_object
  has_many :determiners, through: :determiner_roles, source: :person

  # validates :biological_collection_object, presence: true
  # validates :otu, presence: true
  # # TODO - probably bad, and preventing nested determinations, should just use DB validation

  accepts_nested_attributes_for :determiners
  accepts_nested_attributes_for :determiner_roles, allow_destroy: true

  # accepts_nested_attributes_for :biological_collection_object
  accepts_nested_attributes_for :otu, allow_destroy: false, reject_if: :reject_otu

  validates :year_made, date_year: { min_year: 1757, max_year: Time.now.year }
  validates :month_made, date_month: true
  validates :day_made, date_day: {year_sym: :year_made, month_sym: :month_made}, unless: -> {year_made.nil? || month_made.nil?}

  before_save :set_made_fields_if_not_provided
  after_create :sort_to_top

  # @return [Object]
  def sort_to_top
    reload
    self.move_to_top
  end

  # @return [String]
  def date
    [year_made, month_made, day_made].compact.join('-')
  end

  # @return [Time]
  def sort_date
    Utilities::Dates.nomenclature_date(day_made, month_made, year_made)
  end

  # @param [ActionController::Parameters] params
  # @return [Scope]
  def self.find_for_autocomplete(params)
    where(id: params[:term]).with_project_id(params[:project_id])
  end

  protected

  # @param [Hash] attributed
  # @return [Boolean]
  def reject_otu(attributed)
    attributed['name'].blank? && attributed['taxon_name_id'].blank?
  end

  # @return [Boolean] always true
  def set_made_fields_if_not_provided
    if self.year_made.blank? && self.month_made.blank? && self.day_made.blank?
      self.year_made  = Time.now.year
      self.month_made = Time.now.month
      self.day_made   = Time.now.day
    end
    true
  end

end

- (Integer) otu_id

the OTU (concept) of the determination

Returns:

  • (Integer)


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
# File 'app/models/taxon_determination.rb', line 36

class TaxonDetermination < ApplicationRecord
  acts_as_list scope: [:biological_collection_object_id]

  include Housekeeping
  include Shared::Citations
  include Shared::DataAttributes
  include Shared::Notes
  include Shared::Confidences
  include Shared::HasRoles
  include Shared::IsData

  belongs_to :otu, inverse_of: :taxon_determinations
  belongs_to :biological_collection_object, class_name: 'CollectionObject', inverse_of: :taxon_determinations, foreign_key: :biological_collection_object_id

  has_many :determiner_roles, class_name: 'Determiner', as: :role_object
  has_many :determiners, through: :determiner_roles, source: :person

  # validates :biological_collection_object, presence: true
  # validates :otu, presence: true
  # # TODO - probably bad, and preventing nested determinations, should just use DB validation

  accepts_nested_attributes_for :determiners
  accepts_nested_attributes_for :determiner_roles, allow_destroy: true

  # accepts_nested_attributes_for :biological_collection_object
  accepts_nested_attributes_for :otu, allow_destroy: false, reject_if: :reject_otu

  validates :year_made, date_year: { min_year: 1757, max_year: Time.now.year }
  validates :month_made, date_month: true
  validates :day_made, date_day: {year_sym: :year_made, month_sym: :month_made}, unless: -> {year_made.nil? || month_made.nil?}

  before_save :set_made_fields_if_not_provided
  after_create :sort_to_top

  # @return [Object]
  def sort_to_top
    reload
    self.move_to_top
  end

  # @return [String]
  def date
    [year_made, month_made, day_made].compact.join('-')
  end

  # @return [Time]
  def sort_date
    Utilities::Dates.nomenclature_date(day_made, month_made, year_made)
  end

  # @param [ActionController::Parameters] params
  # @return [Scope]
  def self.find_for_autocomplete(params)
    where(id: params[:term]).with_project_id(params[:project_id])
  end

  protected

  # @param [Hash] attributed
  # @return [Boolean]
  def reject_otu(attributed)
    attributed['name'].blank? && attributed['taxon_name_id'].blank?
  end

  # @return [Boolean] always true
  def set_made_fields_if_not_provided
    if self.year_made.blank? && self.month_made.blank? && self.day_made.blank?
      self.year_made  = Time.now.year
      self.month_made = Time.now.month
      self.day_made   = Time.now.day
    end
    true
  end

end

- (Integer) position

Returns for acts_as_list, !! the determinations with the smallest position is the current/preferred determination, i.e. the one that you want to be seen for the collection object, it is NOT necessarily the most recent determination made

Returns:

  • (Integer)

    for acts_as_list, !! the determinations with the smallest position is the current/preferred determination, i.e. the one that you want to be seen for the collection object, it is NOT necessarily the most recent determination made



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
# File 'app/models/taxon_determination.rb', line 36

class TaxonDetermination < ApplicationRecord
  acts_as_list scope: [:biological_collection_object_id]

  include Housekeeping
  include Shared::Citations
  include Shared::DataAttributes
  include Shared::Notes
  include Shared::Confidences
  include Shared::HasRoles
  include Shared::IsData

  belongs_to :otu, inverse_of: :taxon_determinations
  belongs_to :biological_collection_object, class_name: 'CollectionObject', inverse_of: :taxon_determinations, foreign_key: :biological_collection_object_id

  has_many :determiner_roles, class_name: 'Determiner', as: :role_object
  has_many :determiners, through: :determiner_roles, source: :person

  # validates :biological_collection_object, presence: true
  # validates :otu, presence: true
  # # TODO - probably bad, and preventing nested determinations, should just use DB validation

  accepts_nested_attributes_for :determiners
  accepts_nested_attributes_for :determiner_roles, allow_destroy: true

  # accepts_nested_attributes_for :biological_collection_object
  accepts_nested_attributes_for :otu, allow_destroy: false, reject_if: :reject_otu

  validates :year_made, date_year: { min_year: 1757, max_year: Time.now.year }
  validates :month_made, date_month: true
  validates :day_made, date_day: {year_sym: :year_made, month_sym: :month_made}, unless: -> {year_made.nil? || month_made.nil?}

  before_save :set_made_fields_if_not_provided
  after_create :sort_to_top

  # @return [Object]
  def sort_to_top
    reload
    self.move_to_top
  end

  # @return [String]
  def date
    [year_made, month_made, day_made].compact.join('-')
  end

  # @return [Time]
  def sort_date
    Utilities::Dates.nomenclature_date(day_made, month_made, year_made)
  end

  # @param [ActionController::Parameters] params
  # @return [Scope]
  def self.find_for_autocomplete(params)
    where(id: params[:term]).with_project_id(params[:project_id])
  end

  protected

  # @param [Hash] attributed
  # @return [Boolean]
  def reject_otu(attributed)
    attributed['name'].blank? && attributed['taxon_name_id'].blank?
  end

  # @return [Boolean] always true
  def set_made_fields_if_not_provided
    if self.year_made.blank? && self.month_made.blank? && self.day_made.blank?
      self.year_made  = Time.now.year
      self.month_made = Time.now.month
      self.day_made   = Time.now.day
    end
    true
  end

end

- (Integer) project_id

the project ID

Returns:

  • (Integer)


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
# File 'app/models/taxon_determination.rb', line 36

class TaxonDetermination < ApplicationRecord
  acts_as_list scope: [:biological_collection_object_id]

  include Housekeeping
  include Shared::Citations
  include Shared::DataAttributes
  include Shared::Notes
  include Shared::Confidences
  include Shared::HasRoles
  include Shared::IsData

  belongs_to :otu, inverse_of: :taxon_determinations
  belongs_to :biological_collection_object, class_name: 'CollectionObject', inverse_of: :taxon_determinations, foreign_key: :biological_collection_object_id

  has_many :determiner_roles, class_name: 'Determiner', as: :role_object
  has_many :determiners, through: :determiner_roles, source: :person

  # validates :biological_collection_object, presence: true
  # validates :otu, presence: true
  # # TODO - probably bad, and preventing nested determinations, should just use DB validation

  accepts_nested_attributes_for :determiners
  accepts_nested_attributes_for :determiner_roles, allow_destroy: true

  # accepts_nested_attributes_for :biological_collection_object
  accepts_nested_attributes_for :otu, allow_destroy: false, reject_if: :reject_otu

  validates :year_made, date_year: { min_year: 1757, max_year: Time.now.year }
  validates :month_made, date_month: true
  validates :day_made, date_day: {year_sym: :year_made, month_sym: :month_made}, unless: -> {year_made.nil? || month_made.nil?}

  before_save :set_made_fields_if_not_provided
  after_create :sort_to_top

  # @return [Object]
  def sort_to_top
    reload
    self.move_to_top
  end

  # @return [String]
  def date
    [year_made, month_made, day_made].compact.join('-')
  end

  # @return [Time]
  def sort_date
    Utilities::Dates.nomenclature_date(day_made, month_made, year_made)
  end

  # @param [ActionController::Parameters] params
  # @return [Scope]
  def self.find_for_autocomplete(params)
    where(id: params[:term]).with_project_id(params[:project_id])
  end

  protected

  # @param [Hash] attributed
  # @return [Boolean]
  def reject_otu(attributed)
    attributed['name'].blank? && attributed['taxon_name_id'].blank?
  end

  # @return [Boolean] always true
  def set_made_fields_if_not_provided
    if self.year_made.blank? && self.month_made.blank? && self.day_made.blank?
      self.year_made  = Time.now.year
      self.month_made = Time.now.month
      self.day_made   = Time.now.day
    end
    true
  end

end

- (Integer) year_made

Returns the 4 digit year the determination was made

Returns:

  • (Integer)

    the 4 digit year the determination was made



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
# File 'app/models/taxon_determination.rb', line 36

class TaxonDetermination < ApplicationRecord
  acts_as_list scope: [:biological_collection_object_id]

  include Housekeeping
  include Shared::Citations
  include Shared::DataAttributes
  include Shared::Notes
  include Shared::Confidences
  include Shared::HasRoles
  include Shared::IsData

  belongs_to :otu, inverse_of: :taxon_determinations
  belongs_to :biological_collection_object, class_name: 'CollectionObject', inverse_of: :taxon_determinations, foreign_key: :biological_collection_object_id

  has_many :determiner_roles, class_name: 'Determiner', as: :role_object
  has_many :determiners, through: :determiner_roles, source: :person

  # validates :biological_collection_object, presence: true
  # validates :otu, presence: true
  # # TODO - probably bad, and preventing nested determinations, should just use DB validation

  accepts_nested_attributes_for :determiners
  accepts_nested_attributes_for :determiner_roles, allow_destroy: true

  # accepts_nested_attributes_for :biological_collection_object
  accepts_nested_attributes_for :otu, allow_destroy: false, reject_if: :reject_otu

  validates :year_made, date_year: { min_year: 1757, max_year: Time.now.year }
  validates :month_made, date_month: true
  validates :day_made, date_day: {year_sym: :year_made, month_sym: :month_made}, unless: -> {year_made.nil? || month_made.nil?}

  before_save :set_made_fields_if_not_provided
  after_create :sort_to_top

  # @return [Object]
  def sort_to_top
    reload
    self.move_to_top
  end

  # @return [String]
  def date
    [year_made, month_made, day_made].compact.join('-')
  end

  # @return [Time]
  def sort_date
    Utilities::Dates.nomenclature_date(day_made, month_made, year_made)
  end

  # @param [ActionController::Parameters] params
  # @return [Scope]
  def self.find_for_autocomplete(params)
    where(id: params[:term]).with_project_id(params[:project_id])
  end

  protected

  # @param [Hash] attributed
  # @return [Boolean]
  def reject_otu(attributed)
    attributed['name'].blank? && attributed['taxon_name_id'].blank?
  end

  # @return [Boolean] always true
  def set_made_fields_if_not_provided
    if self.year_made.blank? && self.month_made.blank? && self.day_made.blank?
      self.year_made  = Time.now.year
      self.month_made = Time.now.month
      self.day_made   = Time.now.day
    end
    true
  end

end

Class Method Details

+ (Scope) find_for_autocomplete(params)

Parameters:

  • params (ActionController::Parameters)

Returns:

  • (Scope)


88
89
90
# File 'app/models/taxon_determination.rb', line 88

def self.find_for_autocomplete(params)
  where(id: params[:term]).with_project_id(params[:project_id])
end

Instance Method Details

- (String) date

Returns:

  • (String)


77
78
79
# File 'app/models/taxon_determination.rb', line 77

def date
  [year_made, month_made, day_made].compact.join('-')
end

- (Boolean) reject_otu(attributed) (protected)

Parameters:

  • attributed (Hash)

Returns:

  • (Boolean)


96
97
98
# File 'app/models/taxon_determination.rb', line 96

def reject_otu(attributed)
  attributed['name'].blank? && attributed['taxon_name_id'].blank?
end

- (Boolean) set_made_fields_if_not_provided (protected)

Returns always true

Returns:

  • (Boolean)

    always true



101
102
103
104
105
106
107
108
# File 'app/models/taxon_determination.rb', line 101

def set_made_fields_if_not_provided
  if self.year_made.blank? && self.month_made.blank? && self.day_made.blank?
    self.year_made  = Time.now.year
    self.month_made = Time.now.month
    self.day_made   = Time.now.day
  end
  true
end

- (Time) sort_date

Returns:

  • (Time)


82
83
84
# File 'app/models/taxon_determination.rb', line 82

def sort_date
  Utilities::Dates.nomenclature_date(day_made, month_made, year_made)
end

- (Object) sort_to_top

Returns:

  • (Object)


71
72
73
74
# File 'app/models/taxon_determination.rb', line 71

def sort_to_top
  reload
  self.move_to_top
end