Class: Ekylibre::EquipmentsJsonExchanger

Inherits:
ActiveExchanger::Base show all
Defined in:
app/exchangers/ekylibre/equipments_json_exchanger.rb

Instance Attribute Summary

Attributes inherited from ActiveExchanger::Base

#file, #supervisor

Instance Method Summary collapse

Methods inherited from ActiveExchanger::Base

build, check, check_by_default, exchanger_name, export, exporters, find, human_name, import, import!, importers, importers_selection, inherited, #initialize, register_exchanger

Constructor Details

This class inherits a constructor from ActiveExchanger::Base

Instance Method Details

#importObject

def check

valid = true
clusters = JSON.parse(file.read).deep_symbolize_keys
unless clusters[:type] == 'FeatureCollection'
  w.error 'Invalid format'
  valid = false
end
valid

end


12
13
14
15
16
17
18
19
# File 'app/exchangers/ekylibre/equipments_json_exchanger.rb', line 12

def import
  equipments = JSON.parse(file.read)
  equipments.each do |equipment|
    variant = ProductNatureVariant.import_from_nomenclature(equipment['type'])
    storage = Product.find_by(name: equipment['zone'])
    Equipment.create!(equipment.slice('name').merge(initial_container: storage, default_storage: storage, variant: variant))
  end
end