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

Instance Method Details

#annotation_metadata(project_id = nil) ⇒ Hash

Returns:

  • (Hash)


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
# File 'app/models/concerns/shared/is_data/annotation.rb', line 71

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

#annotationsHash

Returns an accessor for the annotations_hash, overwritten by some inheriting classes.

Returns:

  • (Hash)

    an accessor for the annotations_hash, overwritten by some inheriting classes



66
67
68
# File 'app/models/concerns/shared/is_data/annotation.rb', line 66

def annotations
  annotations_hash
end

#annotations_hashHash (protected)

Contains all “annotations” for this instance

Returns:

  • (Hash)


106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'app/models/concerns/shared/is_data/annotation.rb', line 106

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'] = tags if has_tags? && tags.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_typesObject



53
54
55
56
57
# File 'app/models/concerns/shared/is_data/annotation.rb', line 53

def available_annotation_types
  ::ANNOTATION_TYPES.select do |a|
    self.send("has_#{a}?")
  end
end

#has_loans?Boolean

Doesn’t belong here

Returns:

  • (Boolean)


60
61
62
# File 'app/models/concerns/shared/is_data/annotation.rb', line 60

def has_loans?
  self.class < Shared::Loanable ? true : false
end