Class: ExportHelper::ContextConverter
- Inherits:
-
Object
- Object
- ExportHelper::ContextConverter
- Defined in:
- frontend/app/helpers/export_helper.rb
Overview
Creates a “context” string intended to match what is displayed in the Staff UI for search results.
Class Method Summary collapse
-
.ancestor_fields ⇒ Object
There are several different fields that ‘context’ data may potentially be drawn from.
Instance Method Summary collapse
-
#convert_ancestors_to_context(old_csv) ⇒ Object
-
#initialize ⇒ ContextConverter
constructor
A new instance of ContextConverter.
Constructor Details
#initialize ⇒ ContextConverter
Returns a new instance of ContextConverter.
49 50 51 52 53 |
# File 'frontend/app/helpers/export_helper.rb', line 49 def initialize # Fetching JSONModel records from the backend creates a lot of overhead, and it's likely that many records have # the same ancestor(s), so we'll cache the titles to mitigate that. @title_cache = {} end |
Class Method Details
.ancestor_fields ⇒ Object
There are several different fields that ‘context’ data may potentially be drawn from
45 46 47 |
# File 'frontend/app/helpers/export_helper.rb', line 45 def self.ancestor_fields ['ancestors', 'linked_instance_uris', 'linked_record_uris', 'collection_uri_u_sstr', 'digital_object'] end |
Instance Method Details
#convert_ancestors_to_context(old_csv) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'frontend/app/helpers/export_helper.rb', line 55 def convert_ancestors_to_context(old_csv) # we want all the columns from the search except for the various ancestor fields, which will all end up in context new_csv = [old_csv[0].reject {|header| self.class.ancestor_fields.include? header}] new_csv[0].append 'context' new_row_length = new_csv[0].length context_column_index = new_csv[0].index 'context' column_map = [] old_csv[0].each_with_index do |old_column, old_column_index| new_column_index = new_csv[0].index(old_column) if new_column_index column_map[old_column_index] = new_column_index else column_map[old_column_index] = context_column_index end end old_csv[1...old_csv.length].each do |old_row| new_row = Array.new(new_row_length) column_map.each_with_index do |new_column_index, old_column_index| if new_column_index == context_column_index # these ones need to be moved to the context column if they exist uris = old_row[old_column_index] new_row[new_column_index] = context_string(uris.split ',') unless uris.blank? else new_row[new_column_index] = old_row[old_column_index] end end new_csv.append new_row end new_csv end |