Class: BatchLoad::Import::CollectingEvents::GpxInterpreter

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

Instance Attribute Summary

Attributes inherited from BatchLoad::Import

#create_attempted, #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

- (GpxInterpreter) initialize(**args)

SAVE_ORDER = [:georeference, :collecting_event]



6
7
8
9
10
# File 'lib/batch_load/import/collecting_events/gpx_interpreter.rb', line 6

def initialize(**args)
  @collecting_events = {}
  @ce_namespace = args.delete(:ce_namespace)
  super(args)
end

Instance Method Details

- (Object) build



65
66
67
68
69
70
# File 'lib/batch_load/import/collecting_events/gpx_interpreter.rb', line 65

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

- (Object) build_collecting_events

TODO: update this



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
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/batch_load/import/collecting_events/gpx_interpreter.rb', line 20

def build_collecting_events
  @total_data_lines = 0
  i = 0

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

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

    @processed_rows[i] = parse_result

    begin
      start_date = row['start_date']
      end_date = row['end_date']
      min_elev = row['minimum_elevation']
      max_elev = row['maximum_elevation']

      # blocked by helper methods: Issue #800
      verbatim_date = nil
      verbatim_date = "#{start_date}" if start_date.present?
      verbatim_date += " to #{end_date}" if end_date.present?

      ce_attributes = {verbatim_label: row['name'],
                       verbatim_date: verbatim_date,
                       minimum_elevation: min_elev,
                       maximum_elevation: max_elev}

      geo_json = row['geojson']

      unless geo_json.blank?
        ce_attributes[:gpx_georeferences_attributes] = [{geographic_item_attributes: {shape: geo_json}}]
      end

      ce = CollectingEvent.new(ce_attributes)
      parse_result.objects[:collecting_event] << ce
      @total_lines = i
    rescue
      # ....
    end

  end
end

- (Hash?) csv

methode override for GPX processing which is quite different from CSV

Returns:

  • (Hash, nil)


15
16
17
# File 'lib/batch_load/import/collecting_events/gpx_interpreter.rb', line 15

def csv
  @csv = GPXToCSV.gpx_to_csv(GPX::GPXFile.new(gpx_file: @file.tempfile.path))
end