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, deprecated?, exchanger_name, export, exporters, find, find_and_import, find_by, 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


13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/exchangers/ekylibre/equipments_json_exchanger.rb', line 13

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'])
    attributes = { initial_container: storage,
                   default_storage: storage,
                   initial_born_at: Entity.of_company.born_at,
                   variant: variant }
    Equipment.create!(equipment.slice('name').merge(attributes))
  end
end