Class: BatchLoad::Import::Otus

Inherits:
BatchLoad::Import show all
Defined in:
lib/batch_load/import/otus.rb

Overview

TODO: Originally transliterated from Import::CollectionObjects: Remove this to-do after successful operation.

Defined Under Namespace

Classes: IdentifiersInterpreter

Instance Attribute Summary (collapse)

Attributes inherited from BatchLoad::Import

#create_attempted, #csv, #errors, #file, #file_errors, #import_level, #processed, #processed_rows, #project, #successful_rows, #total_data_lines, #total_lines, #user, #user_header_map

Instance Method Summary (collapse)

Methods inherited from BatchLoad::Import

#all_objects, #create, #create_attempted?, #import_level_ok?, #line_strict_level_ok?, #processed?, #ready_to_create?, #sorted_processed_rows, #strict_level_ok?, #total_records_created, #user_map, #valid?, #valid_objects, #warn_level_ok?

Constructor Details

- (Otus) initialize(**args)

Returns a new instance of Otus

Parameters:

  • args (Hash)


10
11
12
13
# File 'lib/batch_load/import/otus.rb', line 10

def initialize(**args)
  @otus = {}
  super(args)
end

Instance Attribute Details

- (Object) otus

Returns the value of attribute otus



7
8
9
# File 'lib/batch_load/import/otus.rb', line 7

def otus
  @otus
end

Instance Method Details

- (Boolean) build

Returns:

  • (Boolean)


50
51
52
53
54
55
# File 'lib/batch_load/import/otus.rb', line 50

def build
  if valid?
    build_otus
    @processed = true
  end
end

- (Integer) build_otus

Returns:

  • (Integer)


16
17
18
19
20
21
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
# File 'lib/batch_load/import/otus.rb', line 16

def build_otus
  # test_build
  build_objects = {}
  i             = 1 # accounting for headers
  csv.each do |row|
    parse_result = BatchLoad::RowParse.new
    # creation of the possible-objects list
    parse_result.objects[:otu] = []
    # attach the results to the row
    @processed_rows[i] = parse_result

    temp_row               = row
    temp_row['project_id'] = @project_id.to_s if row['project_id'].blank?

    begin # processing the Otu
      otu            = nil
      otu_attributes = {name: row['otu_name']}
      unless otu_attributes[:name].blank?
        otu_list  = BatchLoad::ColumnResolver.otu(temp_row)
        otu       = otu_list.item if otu_list.resolvable?
        otu_match = Digest::SHA256.digest(otu_attributes.to_s)
        otu       = build_objects[otu_match] if otu.blank?
        otu       = Otu.new(otu_attributes) if otu.blank?
        build_objects[otu_match] = otu
        parse_result.objects[:otu].push(otu)
      end
    end

    i += 1
  end
  @total_lines = i - 1
end