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
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 |
# File 'app/models/concerns/shared/is_data/annotation.rb', line 116 def (project_id = nil) h = {} # Use a fixed order for UI stability ANNOTATION_TYPES.each do |t| next unless available_annotation_types.include?(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 h end |
#annotations ⇒ Hash
Returns an accessor for the annotations_hash, overwritten by some inheriting classes.
111 112 113 |
# File 'app/models/concerns/shared/is_data/annotation.rb', line 111 def annotations annotations_hash end |
#annotations_hash ⇒ Hash (protected)
Contains all “annotations” for this instance
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'app/models/concerns/shared/is_data/annotation.rb', line 152 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['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
98 99 100 101 102 |
# File 'app/models/concerns/shared/is_data/annotation.rb', line 98 def available_annotation_types ::ANNOTATION_TYPES.select do |a| self.send("has_#{a}?") end end |
#has_loans? ⇒ Boolean
Doesn’t belong here
105 106 107 |
# File 'app/models/concerns/shared/is_data/annotation.rb', line 105 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
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 |
# File 'app/models/concerns/shared/is_data/annotation.rb', line 40 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 |