Class: BatchLoad::Import::CollectingEvents::GPXInterpreter
- Inherits:
-
BatchLoad::Import
- Object
- BatchLoad::Import
- BatchLoad::Import::CollectingEvents::GPXInterpreter
- 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, #project_id, #successful_rows, #total_data_lines, #total_lines, #user, #user_header_map, #user_id
Instance Method Summary collapse
- #build ⇒ Object
-
#build_collecting_events ⇒ Object
TODO: update this.
-
#csv ⇒ Hash?
methode override for GPX processing which is quite different from CSV.
-
#initialize(**args) ⇒ GPXInterpreter
constructor
SAVE_ORDER = [:georeference, :collecting_event].
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) ⇒ GPXInterpreter
SAVE_ORDER = [:georeference, :collecting_event]
5 6 7 8 9 |
# File 'lib/batch_load/import/collecting_events/gpx_interpreter.rb', line 5 def initialize(**args) @collecting_events = {} @ce_namespace = args.delete(:ce_namespace) super(**args) end |
Instance Method Details
#build ⇒ Object
64 65 66 67 68 69 |
# File 'lib/batch_load/import/collecting_events/gpx_interpreter.rb', line 64 def build if valid? build_collecting_events @processed = true end end |
#build_collecting_events ⇒ Object
TODO: update this
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 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/batch_load/import/collecting_events/gpx_interpreter.rb', line 19 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:, minimum_elevation: min_elev, maximum_elevation: max_elev} geo_json = row['geojson'] if geo_json.present? 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 |
#csv ⇒ Hash?
methode override for GPX processing which is quite different from CSV
14 15 16 |
# File 'lib/batch_load/import/collecting_events/gpx_interpreter.rb', line 14 def csv @csv = Vendor::GPXToCSV.gpx_to_csv(GPX::GPXFile.new(gpx_file: @file.tempfile.path)) end |