opencdd 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2fef2d0d21f84980a8ecd470525ad52e687f511de1ca0c0567b08d55ca63d138
4
- data.tar.gz: b5497fc0a22a1ccedabc62ed3424a99164e2c6b964cd049f5b139a2060316fbc
3
+ metadata.gz: 9fc81f8bcb07863fa5c69e681de61f2d198f39bc81a0fc59da37ec987c9b2a1f
4
+ data.tar.gz: 90e951f6174389ecab19ae8170b3e23ed8ff3e7d79602505f9ae2bd517369384
5
5
  SHA512:
6
- metadata.gz: f4d40389beaf651c46c1acebf77d557ea6ee0b722e6048914bf5e9107937e82aadb65ed7cdce2ae421984cfabf722303145f9dd69c9715fdcabec6d94811da43
7
- data.tar.gz: '083684e0064e581c101c3a906dca0e25e33d06c96c75d1170eef5b46c7a77a5380fb7ebd1d9782b7fac5602086ca0e44d74d7824cc39726c9a12f3f353686f00'
6
+ metadata.gz: c20ebb47fc6253b09cc1dc083066aadb552af65606c77400c932a3f78ac1ee08e78b431eb69a7409a1c9ec9dd2059b7d6d3a6ce78c0143393b6fd80f8c6a89dc
7
+ data.tar.gz: 50c2e7547728041faa53a8acc143e545628e5d3750d61dd55b36e2cd7ec980ee0a7af4755e2fafd8024f0d67a9e4c9cdb9f2140274ae893d8aba29906d26f185
@@ -69,6 +69,17 @@ module Opencdd
69
69
  def self.from_row(row, schema:, meta_class_irdi:, code_property_id: nil)
70
70
  code_property_id ||= default_code_property_id(meta_class_irdi)
71
71
  raw_code = code_property_id && row[code_property_id]
72
+ # Fall back to other known code property IDs when the entity-
73
+ # specific one is absent (happens with name-only header sheets
74
+ # where "Code" synthesizes to MDC_P001_5 regardless of type).
75
+ if raw_code.nil? || raw_code.to_s.strip.empty?
76
+ Opencdd::MetaClasses::CODE_PROPERTY_IDS.each_value do |alt_id|
77
+ val = row[alt_id]
78
+ next if val.nil? || val.to_s.strip.empty?
79
+ raw_code = val
80
+ break
81
+ end
82
+ end
72
83
  irdi = raw_code && Opencdd::IRDI.parse(raw_code)
73
84
 
74
85
  props = row.each_with_object({}) do |(k, v), h|
@@ -79,6 +79,7 @@ module Opencdd
79
79
  "MDC_C011" => "MDC_P001_13",
80
80
  "MDC_C009" => "MDC_P001_10",
81
81
  "MDC_C010" => "MDC_P001_11",
82
+ "MDC_C0100" => "C0101",
82
83
  "EXT_C001" => "EXT_P001",
83
84
  }.freeze
84
85
 
@@ -89,6 +90,7 @@ module Opencdd
89
90
  "MDC_C011" => :relation,
90
91
  "MDC_C009" => :unit,
91
92
  "MDC_C010" => :value_term,
93
+ "MDC_C0100" => :list_of_unit,
92
94
  "EXT_C001" => :view_control,
93
95
  }.freeze
94
96
 
@@ -252,6 +254,13 @@ module Opencdd
252
254
  type: :view_control,
253
255
  allowed_property_ids: common + %w[EXT_P002 EXT_P003],
254
256
  )
257
+ list_of_unit = MetaClass.new(
258
+ irdi: "MDC_C0100",
259
+ name: "ListOfUnit",
260
+ entity_class: Opencdd::Entity,
261
+ type: :list_of_unit,
262
+ allowed_property_ids: common,
263
+ )
255
264
  {
256
265
  klass_class.irdi => klass_class,
257
266
  property_class.irdi => property_class,
@@ -260,6 +269,7 @@ module Opencdd
260
269
  unit.irdi => unit,
261
270
  value_term.irdi => value_term,
262
271
  view_control.irdi => view_control,
272
+ list_of_unit.irdi => list_of_unit,
263
273
  }
264
274
  end
265
275
  end
@@ -23,6 +23,7 @@ module Opencdd
23
23
  "UNIT" => :unit,
24
24
  "VALUELIST" => :value_list,
25
25
  "VALUETERMS" => :value_term,
26
+ "LISTOFUNITS" => :list_of_unit,
26
27
  }.freeze
27
28
 
28
29
  attr_reader :path
@@ -32,7 +32,7 @@ module Opencdd
32
32
 
33
33
  # Per-type export filename produced by cdd.iec.ch's download
34
34
  # endpoint.
35
- FILE_PATTERN = /\Aexport_(CLASS|PROPERTY|RELATION|UNIT|VALUELIST|VALUETERMS)_[^\.]+\.(xls|xlsx)\z/i.freeze
35
+ FILE_PATTERN = /\Aexport_(CLASS|PROPERTY|RELATION|UNIT|VALUELIST|VALUETERMS|LISTOFUNITS)_[^\.]+\.(xls|xlsx)\z/i.freeze
36
36
 
37
37
  module_function
38
38
 
@@ -159,6 +159,9 @@ module Opencdd
159
159
 
160
160
  def finalize!
161
161
  ids = @column_directives["PROPERTY_ID"] || []
162
+ if ids.empty? || ids.all? { |id| id.nil? || id.to_s.strip.empty? }
163
+ ids = synthesize_ids_from_names
164
+ end
162
165
  ids.each_with_index do |id, idx|
163
166
  next if id.nil? || id.to_s.strip.empty?
164
167
 
@@ -194,6 +197,81 @@ module Opencdd
194
197
  freeze
195
198
  end
196
199
 
200
+ # When a sheet has no #PROPERTY_ID directive row (only
201
+ # #PROPERTY_NAME), synthesize property IDs from the names.
202
+ # This happens with some export formats (notably RELATION
203
+ # exports from cdd.iec.ch) that omit the PROPERTY_ID row.
204
+ NAME_TO_PROPERTY_ID = {
205
+ "Code" => "MDC_P001_5",
206
+ "Version" => "MDC_P002_1",
207
+ "Revision" => "MDC_P002_2",
208
+ "VersionInitiationDate" => "MDC_P003_1",
209
+ "VersionReleaseDate" => "MDC_P003_2",
210
+ "RevisionReleaseDate" => "MDC_P003_3",
211
+ "PreferredName" => "MDC_P004",
212
+ "SynonymousName" => "MDC_P007",
213
+ "ShortName" => "MDC_P005",
214
+ "Definition" => "MDC_P006",
215
+ "DefinitionSource" => "MDC_P006_1",
216
+ "Note" => "MDC_P008",
217
+ "Remark" => "MDC_P009",
218
+ "Drawing" => "MDC_P008_1",
219
+ "GUID" => "MDC_P066",
220
+ "TimeStamp" => "MDC_P067",
221
+ "ClassType" => "MDC_P011",
222
+ "Superclass" => "MDC_P010",
223
+ "IsCaseOf" => "MDC_P013",
224
+ "ApplicableProperties" => "MDC_P014",
225
+ "ImportedProperties" => "MDC_P090",
226
+ "SubClassSelection" => "MDC_P016",
227
+ "DataType" => "MDC_P022",
228
+ "ValueFormat" => "MDC_P024",
229
+ "DefinitionClass" => "MDC_P021",
230
+ "Unit" => "MDC_P041",
231
+ "Condition" => "MDC_P028",
232
+ "ListType" => "MDC_P046",
233
+ "CodeList" => "MDC_P044",
234
+ "TermList" => "MDC_P043",
235
+ "EnumerationCode" => "MDC_P044",
236
+ "RelationType" => "MDC_P200",
237
+ "RelationDomain" => "MDC_P201",
238
+ "FunctionDomain" => "MDC_P202",
239
+ "FunctionCodomain" => "MDC_P203",
240
+ "Formula" => "MDC_P204",
241
+ "FormulaLanguage" => "MDC_P205",
242
+ "FormulaExternalSolver" => "MDC_P206",
243
+ "TriggerEvent" => "MDC_P207",
244
+ "DomainElementType" => "MDC_P208",
245
+ "CodomainElementType" => "MDC_P209",
246
+ "Role" => "MDC_P210",
247
+ "Segment" => "MDC_P211",
248
+ "SuperRelation" => "MDC_P212",
249
+ }.freeze
250
+
251
+ def synthesize_ids_from_names
252
+ names = nil
253
+ @column_directives.each do |key, vals|
254
+ base, = key.split(".", 2)
255
+ next unless base == "PROPERTY_NAME"
256
+ names = vals
257
+ break
258
+ end
259
+ return [] unless names
260
+ Array.new(names.size) do |idx|
261
+ val = names[idx]
262
+ next nil if val.nil? || val.to_s.strip.empty?
263
+ raw = val.to_s.strip
264
+ if raw =~ /\A(.+)\.([A-Za-z]{2})\z/
265
+ base = $1
266
+ lang = $2
267
+ pid = NAME_TO_PROPERTY_ID[base]
268
+ pid ? "#{pid}.#{lang.downcase}" : nil
269
+ else
270
+ NAME_TO_PROPERTY_ID[raw]
271
+ end
272
+ end
273
+ end
274
+
197
275
  def [](property_id_or_name)
198
276
  find_by_property_id(property_id_or_name) || find_by_name(property_id_or_name)
199
277
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Opencdd
4
- VERSION = "0.2.1"
4
+ VERSION = "0.2.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opencdd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - OpenCDD contributors