Class: ParentTracker

Inherits:
Object
  • Object
show all
Defined in:
backend/app/lib/bulk_import/parent_tracker.rb

Overview

shamelessly stolen (and adapted) from HM’s nla_staff_spreadsheet plugin :-)

Instance Method Summary collapse

Instance Method Details

#parent_for(hier) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'backend/app/lib/bulk_import/parent_tracker.rb', line 15

def parent_for(hier)
  # Level 1 parent may  be a resource record and therefore nil,
  if hier > 0
    parent_level = hier - 1
    @current_hierarchy.fetch(parent_level, nil)
  else
    nil
  end
end

#set_uri(hier, uri) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'backend/app/lib/bulk_import/parent_tracker.rb', line 3

def set_uri(hier, uri)
  @current_hierarchy ||= {}
  @current_hierarchy = Hash[@current_hierarchy.map { |k, v|
                              if k < hier
                                [k, v]
                              end
                            }.compact]

  # Record the URI of the current record
  @current_hierarchy[hier] = uri
end