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: DataAttributesInterpreter, IdentifiersInterpreter

Constant Summary collapse

SAVE_ORDER =
[:otu]

Instance Attribute Summary collapse

Attributes inherited from BatchLoad::Import

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

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?, #save_order, #sorted_processed_rows, #strict_level_ok?, #total_records_created, #user_map, #valid?, #valid_objects, #warn_level_ok?

Constructor Details

#initialize(**args) ⇒ Otus

Returns a new instance of Otus.

Parameters:

  • args (Hash)


12
13
14
15
# File 'lib/batch_load/import/otus.rb', line 12

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

Instance Attribute Details

#otusObject

Returns the value of attribute otus.



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

def otus
  @otus
end

Instance Method Details

#buildBoolean

Returns:

  • (Boolean)


53
54
55
56
57
58
# File 'lib/batch_load/import/otus.rb', line 53

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

#build_otusInteger

Returns:

  • (Integer)


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
48
49
50
# File 'lib/batch_load/import/otus.rb', line 18

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 !! TODO: if there is no rescue there is no point?
      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