Class: Apidae::Territory
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Apidae::Territory
- Defined in:
- app/models/apidae/territory.rb
Class Method Summary collapse
Class Method Details
.import(territories_json) ⇒ Object
3 4 5 6 7 8 9 10 11 |
# File 'app/models/apidae/territory.rb', line 3 def self.import(territories_json) territories_hashes = JSON.parse(territories_json, symbolize_names: true) territories_hashes.each do |t_data| t = Territory.find_or_initialize_by(apidae_id: t_data[:id]) t.name = t_data.dig(:nom, :libelleFr) t.apidae_type = t_data.dig(:territoireType, :id) t.save! end end |
.import_file(json_file) ⇒ Object
13 14 15 16 |
# File 'app/models/apidae/territory.rb', line 13 def self.import_file(json_file) territories_json = File.read(json_file) import(territories_json) end |