Class: BatchLoad::Import::Otus::IdentifiersInterpreter

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

Instance Attribute Summary

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

Constructor Details

- (IdentifiersInterpreter) initialize(**args)

Returns a new instance of IdentifiersInterpreter

Parameters:

  • args (Hash)


5
6
7
# File 'lib/batch_load/import/otus/identifiers_interpreter.rb', line 5

def initialize(**args)
  super(args)
end

Instance Method Details

- (Boolean) build

Returns:

  • (Boolean)


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

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

- (Integer) build_otus

Returns:

  • (Integer)


10
11
12
13
14
15
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
48
# File 'lib/batch_load/import/otus/identifiers_interpreter.rb', line 10

def build_otus
  @total_data_lines = 0
  i = 0

  # loop throw rows
  csv.each do |row|
    i += 1

    parse_result = BatchLoad::RowParse.new
    parse_result.objects[:otu] = []

    @processed_rows[i] = parse_result

    begin # processing
      otu_identifier_uri_text = row['uri']
      otu_identifier_uri = {
        type: 'Identifier::Global::Uri',
        identifier: otu_identifier_uri_text
      }

      otu_identifiers = []
      otu_identifiers.push(otu_identifier_uri) if otu_identifier_uri_text.present?

      otu_attributes = {
        name: row['name'],
        identifiers_attributes: otu_identifiers
      }

      otu = Otu.new(otu_attributes)
      parse_result.objects[:otu].push otu

      @total_data_lines += 1 if otu.present?
    rescue
        # ....
    end
  end

  @total_lines = i
end