Module: BiologicalAssociationsHelper

Defined in:
app/helpers/biological_associations_helper.rb

Instance Method Summary collapse

Instance Method Details



9
10
11
12
13
14
15
# File 'app/helpers/biological_associations_helper.rb', line 9

def biological_association_link(biological_association)
  return nil if biological_association.nil?
  link_to(object_tag(biological_association.biological_association_subject).html_safe, biological_association.biological_association_subject.metamorphosize) + ' ' +
    link_to((:span, biological_relationship_tag(biological_association.biological_relationship), class: :notice).html_safe, biological_association) + ' ' +
    link_to(object_tag(biological_association.biological_association_object).html_safe, biological_association.biological_association_object.metamorphosize)
  #link_to(biological_association_tag(biological_association).html_safe, biological_association)
end

#biological_association_tag(biological_association) ⇒ Object



3
4
5
6
7
# File 'app/helpers/biological_associations_helper.rb', line 3

def biological_association_tag(biological_association)
  return nil if biological_association.nil?
  object_tag(biological_association.biological_association_subject) + ' ' + (:span, biological_relationship_tag(biological_association.biological_relationship), class: :notice) + ' ' +
    object_tag(biological_association.biological_association_object)
end

#extended_hash(biological_associations) ⇒ Object



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
# File 'app/helpers/biological_associations_helper.rb', line 64

def extended_hash(biological_associations)
  h = []

  biological_associations.each do |b|
    types = biological_relationship_types(b.biological_relationship)

    r = %I{order family genus}.inject({}) { |hsh, r| hsh[('subject_' + r.to_s).to_sym] = [b.biological_association_subject.taxonomy[r.to_s]].flatten.compact.join(' '); hsh }
     r.merge!(
      id: b.id,
      subject_id: b.biological_association_subject_id,
      subject_taxon_name_id: b.biological_association_subject.taxon_name_id,
      subject_type: b.biological_association_subject_type,
      subject: label_for(b.biological_association_subject),
      subject_properties: types[:subject].join('|').presence,
      biological_relationship_id: b.biological_relationship_id,
      biological_relationships: label_for(b.biological_relationship),
      object_properties: types[:object].join('|').presence,
      object_id: b.biological_association_object_id,
      object_taxon_name_id: b.biological_association_object.taxon_name_id,
      object_type: b.biological_association_object_type,
      object: label_for(b.biological_association_object),
    )

     r.merge! %I{order family genus}.inject({}) { |hsh, r| hsh[('object_' + r.to_s).to_sym] = [b.biological_association_object.taxonomy[r.to_s]].flatten.compact.join(' '); hsh }
   h.push r
  end

  h
end

#family_by_genus_summary(scope) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/helpers/biological_associations_helper.rb', line 17

def family_by_genus_summary(scope)
  r = { }

  scope.find_each do |o|
    i = o.biological_association_subject.taxonomy

    j = o.biological_association_object.taxonomy

    gk = i['kingdom'] || 'unknown'
    g = i['genus']&.compact&.join(' ') || 'unknown'

    fk = j['kingdom'] || 'unknown'
    f = j['family'] || 'unknown'

    r[gk] ||= {}
    r[gk][g] ||= {}
    r[gk][g][fk] ||= {}
    r[gk][g][fk][f] ||= 0
    r[gk][g][fk][f] += 1
  end

  r
end

#simple_hash(biological_associations) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/helpers/biological_associations_helper.rb', line 41

def simple_hash(biological_associations)
  h = []

  biological_associations.each do |b|
    types = biological_relationship_types(b.biological_relationship)

    r = %I{order family genus}.inject({}) { |hsh, r| hsh[('subject_' + r.to_s).to_sym] = [b.biological_association_subject.taxonomy[r.to_s]].flatten.compact.join(' '); hsh }
     r.merge!(
      # types: biological_relationship_types(b.biological_relationship),
      subject: label_for(b.biological_association_subject),
      subject_properties: types[:subject].join('|').presence,
      biological_relationships: label_for(b.biological_relationship),
      object_properties: types[:object].join('|').presence,
      object: label_for(b.biological_association_object),
    )

     r.merge! %I{order family genus}.inject({}) { |hsh, r| hsh[('object_' + r.to_s).to_sym] = [b.biological_association_object.taxonomy[r.to_s]].flatten.compact.join(' '); hsh }
   h.push r
  end

  h
end