Module: ObservationMatricesHelper

Defined in:
app/helpers/observation_matrices_helper.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) keywords_on_addable_column_items



26
27
28
# File 'app/helpers/observation_matrices_helper.rb', line 26

def keywords_on_addable_column_items
  Keyword.joins(:tags).where(project_id: sessions_current_project_id).where(tags: {tag_object_type: 'Descriptor'}).distinct.all
end

- (Object) keywords_on_addable_row_items



22
23
24
# File 'app/helpers/observation_matrices_helper.rb', line 22

def keywords_on_addable_row_items
  Keyword.joins(:tags).where(project_id: sessions_current_project_id).where(tags: {tag_object_type: ['Otu', 'CollectionObject']}).distinct.all
end

- (Object) max_row_name_width(observation_matrix)

Matrix export helpers



32
33
34
35
36
37
38
39
40
# File 'app/helpers/observation_matrices_helper.rb', line 32

def max_row_name_width(observation_matrix)
  max = 0

  observation_matrix.observation_matrix_rows.load.each do |r|
    s = observation_matrix_row_label(r).length 
    max = s if max < s
  end
  max + 1
end

- (String) observation_export_value(observation)

Returns the value shown in the cell

Returns:

  • (String)

    the value shown in the cell



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'app/helpers/observation_matrices_helper.rb', line 72

def observation_export_value(observation)
  case observation.type
  when 'Observation::Qualitative'
    observation.character_state.label
  when 'Observation::PresenceAbsence' 
    case observation.presence
    when true
      '1'
    when false
      '0'
    when nil
      '?'
    else
      'INTERNAL ERROR'
    end
  when 'Observation::Continuous'
    ## ! TODO: auto convert to descriptor standard units (model method)
    observation.continuous_value.to_s


  else
    '-' # ? not sure 
  end
end

- (Object) observation_matrices_search_form



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

def observation_matrices_search_form
  render('/observation_matrices/quick_search_form')
end

- (Object) observation_matrix_label(observation_matrix)



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

def observation_matrix_label(observation_matrix)
  return nil if observation_matrix.nil?
  observation_matrix.name
end


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

def observation_matrix_link(observation_matrix)
  return nil if observation_matrix.nil?
  link_to(observation_matrix_tag(observation_matrix).html_safe, observation_matrix)
end

- (Object) observation_matrix_tag(observation_matrix)



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

def observation_matrix_tag(observation_matrix)
  return nil if observation_matrix.nil?
  observation_matrix.name
end

- (String) observations_cell_label(observations_hash, descriptor, row_object_global_id, style = :tnt)

Returns the fully formatted cell, handles polymorphisms show states in tnt or nexus format for a 'cell' (e.g. [ab]) Mx.print_codings in mx

Returns:

  • (String)

    the fully formatted cell, handles polymorphisms show states in tnt or nexus format for a 'cell' (e.g. [ab]) Mx.print_codings in mx



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/helpers/observation_matrices_helper.rb', line 46

def observations_cell_label(observations_hash, descriptor, row_object_global_id, style = :tnt)
  case observations_hash[descriptor.id][row_object_global_id].size
  when 0
    "?"
  when 1
    o = observations_hash[descriptor.id][row_object_global_id][0] 
    s = observation_export_value(o)

    if s.length > 1 && style == :nexus && o.type == 'Observation::Qualitative'
      "#{s} [WARNING STATE '#{s}' is TOO LARGE FOR PAUP (0-9, A-Z only).]"
    else
      s
    end
  else
    str = observations_hash[descriptor.id][row_object_global_id].collect{|o| observation_export_value(o) }.sort.join("")
    case style
    when :nexus
      "{#{str}}"
    else
      "[#{str}]"
    end
  end
end