Module: DescriptorsHelper

Defined in:
app/helpers/descriptors_helper.rb

Instance Method Summary collapse

Instance Method Details



17
18
19
20
# File 'app/helpers/descriptors_helper.rb', line 17

def descriptor_link(descriptor)
  return nil if descriptor.nil?
  link_to(descriptor_tag(descriptor).html_safe, descriptor.metamorphosize)
end

#descriptor_matrix_character_states_label(descriptor) ⇒ String?

Returns state labels formatted for matrix export.

Returns:

  • (String, nil)

    state labels formatted for matrix export



74
75
76
77
78
79
80
# File 'app/helpers/descriptors_helper.rb', line 74

def descriptor_matrix_character_states_label(descriptor)
  if descriptor.qualitative?
    descriptor.character_states.map{|state| state.name.gsub(/[\W]/ , "_")}.join(" ")
  else
    nil
  end
end


54
55
56
57
# File 'app/helpers/descriptors_helper.rb', line 54

def descriptor_matrix_column_link(descriptor)
  z = [descriptor.short_name, descriptor.name].compact.first
  link_to(z, new_descriptor_task_path(descriptor.metamorphosize), data: {help: descriptor.name})
end

#descriptor_matrix_label(descriptor) ⇒ String

Returns the column/descriptor name presented in the exported matrix.

Returns:

  • (String)

    the column/descriptor name presented in the exported matrix



61
62
63
# File 'app/helpers/descriptors_helper.rb', line 61

def descriptor_matrix_label(descriptor)
  descriptor.name.gsub(/[\W]/ , "_")
end

#descriptor_matrix_label_csv(descriptor, quote = '"') ⇒ String

Returns the column/descriptor name modified for comma separated

quote delimited CSV export.

Returns:

  • (String)

    the column/descriptor name modified for comma separated

    quote delimited CSV export
    


68
69
70
# File 'app/helpers/descriptors_helper.rb', line 68

def descriptor_matrix_label_csv(descriptor, quote = '"')
  quote + descriptor.name.gsub('"', "'") + quote
end

#descriptor_tag(descriptor) ⇒ Object



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

def descriptor_tag(descriptor)
  return nil if descriptor.nil?
  descriptor.name
end

#descriptors_autocomplete_tag(descriptor, term = nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/helpers/descriptors_helper.rb', line 22

def descriptors_autocomplete_tag(descriptor, term = nil)
  return nil if descriptor.nil?

  if term
    s = descriptor.name.gsub(/#{Regexp.escape(term)}/i, "<mark>#{term}</mark>")
  else
    s = descriptor.name
  end

  s += ' ' + (:span, descriptor.type.split('::').last, class: [:feedback, 'feedback-secondary', 'feedback-thin'])

  c = descriptor.observations.count
  if c > 0
    s += ' ' + (:span, "#{c.to_s}&nbsp;#{'observation'.pluralize(c)}".html_safe, class: [:feedback, 'feedback-info', 'feedback-thin'])
  end

  d = Observation.joins(:depictions).where(descriptor_id: descriptor.id).count
  if d > 0
    s += ' ' + (:span, "#{d.to_s}&nbsp;#{'observation depiction'.pluralize(d)}".html_safe, class: [:feedback, 'feedback-secondary', 'feedback-thin'])
  end

  e =  descriptor.observation_matrices.count
  s += ' '
  if e > 0
    s +=  (:span, "#{e.to_s}&nbsp;#{'matrix'.pluralize(e)}".html_safe, class: [:feedback, 'feedback-secondary', 'feedback-thin'])
  else
    s += (:span, "No matrix".html_safe, class: [:feedback, 'feedback-warning', 'feedback-thin'])
  end

  s.html_safe
end

#descriptors_search_formObject



13
14
15
# File 'app/helpers/descriptors_helper.rb', line 13

def descriptors_search_form
  render('/descriptors/quick_search_form')
end

#label_for_descriptor(descriptor) ⇒ Object



8
9
10
11
# File 'app/helpers/descriptors_helper.rb', line 8

def label_for_descriptor(descriptor)
  return nil if descriptor.nil?
  descriptor.name
end