Module: ObservationMatricesHelper
- Defined in:
- app/helpers/observation_matrices_helper.rb
Instance Method Summary collapse
- #keywords_on_addable_column_items ⇒ Object
- #keywords_on_addable_row_items ⇒ Object
-
#max_row_name_width(observation_matrix) ⇒ Object
Matrix export helpers.
-
#observation_export_value(observation) ⇒ String
The value shown in the cell.
- #observation_matrices_search_form ⇒ Object
- #observation_matrix_label(observation_matrix) ⇒ Object
- #observation_matrix_link(observation_matrix) ⇒ Object
- #observation_matrix_tag(observation_matrix) ⇒ Object
-
#observations_cell_label(observations_hash, descriptor, row_object_global_id, style = :tnt) ⇒ 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.
Instance Method Details
#keywords_on_addable_column_items ⇒ Object
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 |
#keywords_on_addable_row_items ⇒ Object
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 |
#max_row_name_width(observation_matrix) ⇒ Object
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 |
#observation_export_value(observation) ⇒ String
Returns 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 |
# 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' observation.converted_value.to_s else '-' # ? not sure end end |
#observation_matrices_search_form ⇒ Object
13 14 15 |
# File 'app/helpers/observation_matrices_helper.rb', line 13 def observation_matrices_search_form render('/observation_matrices/quick_search_form') end |
#observation_matrix_label(observation_matrix) ⇒ Object
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 |
#observation_matrix_link(observation_matrix) ⇒ Object
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 |
#observation_matrix_tag(observation_matrix) ⇒ Object
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 |
#observations_cell_label(observations_hash, descriptor, row_object_global_id, style = :tnt) ⇒ String
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.
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 |