Module: Opencdd::Database::ParcelIntegration
- Included in:
- Opencdd::Database
- Defined in:
- lib/opencdd/database/parcel_integration.rb
Overview
Parcel workbook ingestion and dictionary lifecycle (add/drop/ register_external). Sheetmap construction and translation- language parsing.
Instance Method Summary collapse
- #add_dictionary(dict) ⇒ Object
- #add_workbook(workbook) ⇒ Object
- #dictionaries ⇒ Object
- #drop_dictionary(parcel_id) ⇒ Object
- #register_external_sheet(sheet, parcel_id:) ⇒ Object
Instance Method Details
#add_dictionary(dict) ⇒ Object
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 |
# File 'lib/opencdd/database/parcel_integration.rb', line 34 def add_dictionary(dict) validate_parcel_id!(dict.parcel_id) source_language = dict.source_language || "en" translation_languages = Array(dict.translation_languages) = (dict.) sheets = .map do || Opencdd::Parcel::Sheet.scaffold( meta_class_irdi: , parcel_id: dict.parcel_id, source_language: source_language, translation_languages: translation_languages, ) end project = Opencdd::Parcel::Workbook::ProjectInfo.new( project_id: dict.parcel_id, parcel_id: dict.parcel_id, multi_language: translation_languages.join(","), base_language: source_language, ) sheetmap = build_sheetmap_for(dict.parcel_id, sheets) workbook = Opencdd::Parcel::Workbook.new( sheets: sheets, sheetmap: sheetmap, project: project, ) @workbooks << workbook workbook end |
#add_workbook(workbook) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/opencdd/database/parcel_integration.rb', line 9 def add_workbook(workbook) @workbooks << workbook parcel_id = workbook.parcel_id workbook.each_sheet do |sheet| next unless sheet.type && sheet.rows.any? type = sheet.type entity_class = Opencdd::MetaClasses.entity_class_for_type(type) raise "Unknown entity type #{type.inspect} for sheet #{sheet.name.inspect}" unless entity_class sheet.rows.each do |row| entity = entity_class.from_row( row, schema: sheet.schema, meta_class_irdi: sheet., ) add_entity(entity) if parcel_id && entity.irdi prev = @entity_sources[entity.irdi] @entity_sources[entity.irdi] = prev.nil? ? parcel_id : prev end end end self end |
#dictionaries ⇒ Object
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/opencdd/database/parcel_integration.rb', line 91 def dictionaries @workbooks.map do |wb| Dictionary.new( parcel_id: wb.parcel_id, source_language: wb.base_language, translation_languages: parse_translation_languages(wb), meta_class_irdis: wb.sheets.map(&:meta_class_irdi).compact.uniq, ) end end |
#drop_dictionary(parcel_id) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/opencdd/database/parcel_integration.rb', line 63 def drop_dictionary(parcel_id) matching = @workbooks.select { |wb| wb.parcel_id == parcel_id } raise ArgumentError, "no dictionary with parcel_id #{parcel_id.inspect}" if matching.empty? irdis_to_drop = @entity_sources.select { |_, pid| pid == parcel_id }.keys irdis_to_drop.each do |irdi| remove_entity_by_irdi!(irdi) @entity_sources.delete(irdi) end @workbooks.reject! { |wb| wb.parcel_id == parcel_id } self end |
#register_external_sheet(sheet, parcel_id:) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/opencdd/database/parcel_integration.rb', line 76 def register_external_sheet(sheet, parcel_id:) validate_parcel_id!(parcel_id) wb = @workbooks.find { |w| w.parcel_id == parcel_id } if wb.nil? project = Opencdd::Parcel::Workbook::ProjectInfo.new( project_id: parcel_id, parcel_id: parcel_id, multi_language: "", base_language: "en", ) wb = Opencdd::Parcel::Workbook.new(sheets: [], sheetmap: [], project: project) @workbooks << wb end wb.register_sheet(sheet) self end |