Module: Shared::IsData::Annotation
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/shared/is_data/annotation.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #annotation_metadata(project_id = nil) ⇒ Hash
-
#annotations ⇒ Hash
An accessor for the annotations_hash, overwritten by some inheriting classes.
-
#annotations_hash ⇒ Hash
protected
Contains all "annotations" for this instance.
- #available_annotation_types ⇒ Object
-
#has_loans? ⇒ Boolean
Doesn't belong here.
-
#move_annotations(to_object: nil, except: [], only: []) ⇒ Object
TODO: consider implications of allowing cloning from any object to any object.
Instance Method Details
#annotation_metadata(project_id = nil) ⇒ Hash
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 |
# File 'app/models/concerns/shared/is_data/annotation.rb', line 115 def (project_id = nil) h = {} available_annotation_types.each do |t| case t when :documentation if project_id h[:documentation] = {total: documentation.where(documentation: {project_id:}).count} else h[:documentation] = {total: ( send(:documentation).count) } end when :attribution h[:attribution] = {total: (send(:attribution).present? ? 1 : 0)} when :identifiers if project_id h[:identifiers] = {total: ( send(:identifiers).visible(project_id).count)} else h[:identifiers] = {total: ( send(:identifiers).count) } end else h[t] = { total: send(t).count } end end # For display consistency h.sort_by { |key, _value| ANNOTATION_TYPES.index(key) }.to_h end |
#annotations ⇒ Hash
Returns an accessor for the annotations_hash, overwritten by some inheriting classes.
110 111 112 |
# File 'app/models/concerns/shared/is_data/annotation.rb', line 110 def annotations annotations_hash end |
#annotations_hash ⇒ Hash (protected)
Contains all "annotations" for this instance
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'app/models/concerns/shared/is_data/annotation.rb', line 148 def annotations_hash result = {} result['citations'] = citations if has_citations? && citations.load.any? # Use load since we nearly always are going ot reference the result result['data attributes'] = data_attributes if has_data_attributes? && data_attributes.load.any? result['identifiers'] = identifiers if has_identifiers? && identifiers.load.any? # !! TODO: Load is broken here. result['notes'] = notes if has_notes? && notes.load.any? result['tags'] = if && .load.any? result['depictions'] = depictions.order('depictions.position') if has_depictions? && depictions.load.any? result['conveyances'] = conveyances.order('conveyances.position') if has_conveyances? && conveyances.load.any? result['confidences'] = confidences if has_confidences? && confidences.load.any? result['protocol relationships'] = protocols if has_protocol_relationships? && protocolled? result['alternate values'] = alternate_values if has_alternate_values? && alternate_values.load.any? result['attribution'] = attribution if has_attribution? && attribution.load.any? result['verifiers'] = verifiers if has_verifiers? && verifiers.load.any? result end |
#available_annotation_types ⇒ Object
97 98 99 100 101 |
# File 'app/models/concerns/shared/is_data/annotation.rb', line 97 def available_annotation_types ::ANNOTATION_TYPES.select do |a| self.send("has_#{a}?") end end |
#has_loans? ⇒ Boolean
Doesn't belong here
104 105 106 |
# File 'app/models/concerns/shared/is_data/annotation.rb', line 104 def has_loans? self.class < Shared::Loanable ? true : false end |
#move_annotations(to_object: nil, except: [], only: []) ⇒ Object
TODO: consider implications of allowing cloning from any object to any object
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 |
# File 'app/models/concerns/shared/is_data/annotation.rb', line 39 def move_annotations(to_object: nil, except: [], only: []) return false if to_object.nil? e = except.map(&:to_sym) o = only.map(&:to_sym) errors = [] a = !only.empty? ? o : (::ANNOTATION_TYPES - e) a.each do |t| if respond_to?(t) send(t).each do |i| i.annotated_object = to_object begin i.save! rescue ActiveRecord::RecordInvalid => e errors.push e end end end end errors end |