Sha256: 1b521f274a099aed6544da17c50d3fbbe50d3ca284f96bb99db79e666a0c9d7c
Contents?: true
Size: 1.13 KB
Versions: 6
Compression:
Stored size: 1.13 KB
Contents
module Apidae class Reference < ApplicationRecord INTERNAL = 'internal' def self.import(refs_json) refs_hashes = JSON.parse(refs_json, symbolize_names: true) if refs_hashes.length != where("apidae_type != ?", INTERNAL).count refs_hashes.each do |ref_data| ref = Reference.find_or_initialize_by(apidae_id: ref_data[:id], apidae_type: ref_data[:elementReferenceType]) ref.label_data = ref_data.slice(:libelleFr, :libelleEn) ref.save! end end end def self.import_file(json_file) refs_json = File.read(json_file) import(refs_json) end def self.import_internal(internal_json) refs_hashes = JSON.parse(internal_json, symbolize_names: true) if refs_hashes.length != where(apidae_type: INTERNAL).count refs_hashes.each do |ref_data| ref = Reference.find_or_initialize_by(apidae_id: ref_data[:id], apidae_type: INTERNAL) ref.label_data = {libelleFr: ref_data[:libelle]} ref.save! end end end def label(language) label_data["libelle#{language.to_s.upcase_first}"] end end end
Version data entries
6 entries across 6 versions & 1 rubygems