stepmod-utils 0.3.23 → 0.3.24

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: 96740d6528de476007a4f312fa8889887e77a27d4a693924531813188a3cd60b
4
- data.tar.gz: 867240182ffe77c721fe7ffa8ee53b77383db9954cffa9c4de723e652ec90780
3
+ metadata.gz: 92d04b3c30620d813fbff40cfa84ed809f0129440dd1f6be45c4206aaa44a12e
4
+ data.tar.gz: 54289d1067ccba3a61cd0ca07bd5455081efe70aae946811cf8028f6e77afb9a
5
5
  SHA512:
6
- metadata.gz: 6e5b71123d326d72e7f6f64269238e2c0db08cec4033794a1a104088d8ae3c0b7e9b005b2551bb2541b06d676fb6959120a7bd1aac30c3cc63068e581206d8c3
7
- data.tar.gz: 9aba582cd94d7c7b85fd9bc8ad2e718c0bf23f6609a86de46393c55a85bda496fecbe9f8c847fd073a5aa1ca351148917520a490d695769fde21d118428fbe98
6
+ metadata.gz: e83145314175c1797f8de0fe08bdbf3ba95e06346b49f80beb3cdadb31d1b2423cb60230d869b91850de3685b0fb6c805a2b4ddebbfd72ff2b55ffde234f4d9f
7
+ data.tar.gz: 309a341bead6e54225f14101c3bea989f2f7873409c4d8e1fedbc6e8b2144d3e21ed2034c5ebcfd76279d73234a84e8d0d67c86fb77e1e1b715f6f1ba2ad661b
data/.rubocop.yml CHANGED
@@ -6,5 +6,8 @@ inherit_from:
6
6
  # local repo-specific modifications
7
7
  # ...
8
8
 
9
+ Style/MultilineMethodCallIndentation:
10
+ EnforcedStyle: aligned
11
+
9
12
  AllCops:
10
13
  TargetRubyVersion: 2.5
@@ -0,0 +1,149 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require "pry"
5
+ # resolve bin path, ignoring symlinks
6
+ require "pathname"
7
+ bin_file = Pathname.new(__FILE__).realpath
8
+
9
+ # add self to libpath
10
+ $:.unshift File.expand_path("../../lib", bin_file)
11
+
12
+ # Fixes https://github.com/rubygems/rubygems/issues/1420
13
+ require "rubygems/specification"
14
+
15
+ module Gem
16
+ class Specification
17
+ def this; self; end
18
+ end
19
+ end
20
+
21
+ require "bundler/setup"
22
+ require_relative "../lib/stepmod/utils/terms_extractor"
23
+ require "optparse"
24
+
25
+ def log(message)
26
+ puts "[stepmod-utils] #{message}"
27
+ end
28
+
29
+ options = {}
30
+ OptionParser.new do |opts|
31
+ opts.banner = "Usage: #{$0} [options]"
32
+
33
+ opts.on(
34
+ "-p",
35
+ "--path STEPMOD_DATA_PATH",
36
+ String,
37
+ "Path to STEPmod data directory",
38
+ ) do |path|
39
+ options[:stepmod_dir] = path
40
+ end
41
+
42
+ opts.on(
43
+ "-i",
44
+ "--index INDEX_PATH",
45
+ String,
46
+ "Path to repository_index.xml",
47
+ ) do |path|
48
+ unless path.nil?
49
+ options[:index_path] = Pathname.new(path).to_s
50
+ end
51
+ end
52
+
53
+ opts.on_tail("-h", "--help", "Show this message") do
54
+ puts opts
55
+ exit
56
+ end
57
+ end.parse!
58
+
59
+ stepmod_dir = options[:stepmod_dir]
60
+ if stepmod_dir.nil?
61
+ raise StandardError.new(
62
+ "STEPmod data path not set, set with the `-p` option.",
63
+ )
64
+ else
65
+ log "STEPmod data path: `#{stepmod_dir}`"
66
+ end
67
+
68
+ default_index_path = File.join(stepmod_dir, "repository_index.xml")
69
+ index_path = options[:index_path] || default_index_path
70
+ if File.exists?(index_path)
71
+ log "Repository index path: `#{index_path}`"
72
+ else
73
+ raise StandardError.new(
74
+ "Index file not present at #{index_path}, set with the `-i` option.",
75
+ )
76
+ end
77
+
78
+ _general_concepts,
79
+ resource_concepts,
80
+ _parsed_bibliography,
81
+ _part_concepts,
82
+ part_resources,
83
+ part_modules = Stepmod::Utils::TermsExtractor.call(stepmod_dir, index_path)
84
+
85
+ def part_to_title(bibdata)
86
+ {
87
+ 41 => "Fundamentals of product description and support",
88
+ 42 => "Geometric and topological representation",
89
+ 43 => "Foundation representation",
90
+ 44 => "Product structure, concept and configuration",
91
+ 45 => "Material and other engineering properties",
92
+ 46 => "Visual presentation",
93
+ 47 => "Shape tolerance",
94
+ 51 => "Mathematical representation",
95
+ }[bibdata.part.to_i] || bibdata.title_en
96
+ end
97
+
98
+ # rubocop:disable Layout/LineLength
99
+ IMAGE_REPLACEMENTS = {
100
+ "image::eq01.gif[]" => "stem:[H(A,B) = max {h(A, B), h(B,A)}]",
101
+ "image::eq02.gif[]" => "stem:[max_{a in A} { min_{b in B} d(a,b) }]",
102
+ "image::vector_z_c.gif[]" => "stem:[bar z_{c}]",
103
+ "image::one_direction_repeat_factor_expression.gif[]" => "stem:[I + k cdot R; k = -1, 1]",
104
+ "image::two_direction_repeat_factor_expression.gif[]" => "stem:[I + k_1 cdot R_1 + k_2 cdot R_2; k_1, k_2 = -1, 0, 1, k^2_1 + k^2_2 != 0]",
105
+ }.freeze
106
+
107
+ TEXT_REPLACEMENTS = {
108
+ ' (see <module_ref linkend="ply_orientation_specification:4_entities:figure:f2"> Figure 2</module_ref>)' => "",
109
+ ' (see <module_ref linkend="ply_orientation_specification:4_entities:figure:f3"> Figure 3</module_ref>)' => "",
110
+ }.freeze
111
+ # rubocop:enable Layout/LineLength
112
+
113
+ def replace_content(content)
114
+ IMAGE_REPLACEMENTS.each_pair do |k, v|
115
+ content.gsub!(k, v)
116
+ end
117
+ TEXT_REPLACEMENTS.each_pair do |k, v|
118
+ content.gsub!(k, v)
119
+ end
120
+
121
+ content
122
+ end
123
+
124
+ part_resources.each do |(_bibdata, current_part_resources)|
125
+ current_part_resources.save_to_files("./")
126
+ end
127
+ log "INFO: part_resources written to yaml files"
128
+
129
+
130
+ log "INFO: written summary file to: 04x-stepmod-entities-resources.adoc"
131
+ part_modules.sort_by do |(bibdata, _part_modules_arm, _part_modules_mim)|
132
+ bibdata.part.to_i
133
+ end.each do |(_bibdata, part_modules_arm, part_modules_mim)|
134
+ unless part_modules_arm.empty?
135
+ part_modules_arm.values.map do |managed_concept|
136
+ managed_concept.save_to_files("./")
137
+ end
138
+ end
139
+
140
+ unless part_modules_mim.empty?
141
+ part_modules_mim.values.map do |managed_concept|
142
+ managed_concept.save_to_files("./")
143
+ end
144
+ end
145
+ end
146
+ log "INFO: part_modules written to yaml files"
147
+
148
+ resource_concepts.save_to_files("./")
149
+ log "INFO: resource_concepts written to yaml files"
@@ -8,6 +8,10 @@ module Stepmod
8
8
  reference_anchor
9
9
  converted_definition
10
10
  file_path
11
+ schema
12
+ part
13
+ domain
14
+ document
11
15
  )
12
16
 
13
17
  # TODO: converted_definition is not supposed to be an attribute, it is
@@ -40,8 +44,8 @@ module Stepmod
40
44
  # TODO: `designations:` should include the `alt:[...]` terms here,
41
45
  # they are now only included in definition_xml_converted_definition.
42
46
  new(
43
- designations: [designation],
44
- definition: definition,
47
+ designations: designation,
48
+ definition: [definition],
45
49
  converted_definition: converted_definition,
46
50
  id: "#{reference_anchor}.#{reference_clause}",
47
51
  reference_anchor: reference_anchor,
@@ -65,11 +69,16 @@ module Stepmod
65
69
  definition_xml.xpath(".//term").first
66
70
  )
67
71
 
68
- {
69
- # [4..-1] because we want to skip the initial `=== {title}`
70
- accepted: term[4..-1],
71
- alt: alts,
72
- }
72
+ # [4..-1] because we want to skip the initial `=== {title}`
73
+ designations = [
74
+ { "designation" => term[4..-1], "type" => "expression", "normative_status" => "preferred" },
75
+ ]
76
+
77
+ alts.each do |alt|
78
+ designations << { "designation" => alt, "type" => "expression" }
79
+ end
80
+
81
+ designations
73
82
  end
74
83
 
75
84
  def definition_xml_definition(definition_xml, reference_anchor)
@@ -95,12 +104,24 @@ module Stepmod
95
104
  end
96
105
 
97
106
  def definition_xml_converted_definition(designation, definition)
98
- if designation[:alt].length.positive?
99
- alt_notation = "alt:[#{designation[:alt].map(&:strip).join(',')}]"
107
+ accepted_designation = designation.select do |des|
108
+ des["normative_status"] == "preferred"
109
+ end
110
+
111
+ alt_designations = designation.reject do |des|
112
+ des["normative_status"] == "preferred"
113
+ end
114
+
115
+ if alt_designations.length.positive?
116
+ alt_designations_text = alt_designations.map do |d|
117
+ d["designation"].strip
118
+ end.join(",")
119
+
120
+ alt_notation = "alt:[#{alt_designations_text}]"
100
121
  end
101
122
 
102
123
  result = <<~TEXT
103
- === #{designation[:accepted].strip}
124
+ === #{accepted_designation.map { |d| d['designation'].strip }.join(',')}
104
125
  TEXT
105
126
 
106
127
  if alt_notation
@@ -117,6 +138,15 @@ module Stepmod
117
138
  end
118
139
  end
119
140
 
141
+ def to_h
142
+ super.merge({
143
+ "domain" => domain,
144
+ "part" => part,
145
+ "schema" => schema,
146
+ "document" => document,
147
+ }.compact)
148
+ end
149
+
120
150
  def to_mn_adoc
121
151
  <<~TEXT
122
152
  // STEPmod path:#{file_path.empty? ? '' : " #{file_path}"}
@@ -0,0 +1,111 @@
1
+ module Stepmod
2
+ module Utils
3
+ class ExpressBibdata
4
+ DOCNUMBER = 10303
5
+
6
+ attr_accessor *%w(
7
+ type doctype part title_en version pub_year pubid published_info number
8
+ )
9
+
10
+ def initialize(schema:)
11
+ # module, resource, application_protocol, business_object_model
12
+ # @type = document.name
13
+
14
+ # raise "UnknownFileError" unless %w(module resource
15
+ # application_protocol business_object_model).include?(@type)
16
+
17
+ @published_info = schema.find("__published_in")&.remarks&.first
18
+ @number = schema.find("__identifier")&.remarks&.first&.split("N")&.last
19
+ @schema = schema
20
+
21
+ if !published_info.nil?
22
+ @pubid = Pubid::Iso::Identifier.parse(published_info)
23
+
24
+ @part = pubid.part
25
+ @version = pubid.edition
26
+ @pub_year = pubid.year
27
+ elsif !schema.version.nil?
28
+ @part = schema.version.items.find { |i| i.name == "part" }.value
29
+ @version = schema.version.items.find { |i| i.name == "part" }.value
30
+ @pub_year = schema.version.items.find { |i| i.name == "part" }.value
31
+ else
32
+ raise "PublishedInfoNotFound"
33
+ end
34
+
35
+ @doctype = schema.find("__status")&.remarks&.first
36
+ self
37
+ end
38
+
39
+ def title_en
40
+ @title_en ||= @schema.find("__title")
41
+ .remarks
42
+ .first
43
+ .gsub("_", " ")
44
+ .capitalize
45
+ .gsub("2d", "2D")
46
+ .gsub("3d", "3D")
47
+ end
48
+
49
+ def docid
50
+ no_date = case doctype
51
+ when "IS"
52
+ "ISO #{DOCNUMBER}-#{part}"
53
+ when "WD"
54
+ "ISO/WD #{DOCNUMBER}-#{part}"
55
+ when "CD"
56
+ "ISO/CD #{DOCNUMBER}-#{part}"
57
+ when "DIS"
58
+ "ISO/DIS #{DOCNUMBER}-#{part}"
59
+ when "FDIS"
60
+ "ISO/FDIS #{DOCNUMBER}-#{part}"
61
+ when "TS"
62
+ "ISO/TS #{DOCNUMBER}-#{part}"
63
+ when "CD-TS"
64
+ "ISO/CD TS #{DOCNUMBER}-#{part}"
65
+ else
66
+ "UNKNOWN DOCTYPE: (#{doctype})"
67
+ end
68
+
69
+ if pub_year
70
+ "#{no_date}:#{pub_year}"
71
+ else
72
+ no_date
73
+ end
74
+ end
75
+
76
+ def part_title
77
+ case part
78
+ when [200..299]
79
+ "Application protocol: #{title_en}"
80
+ when [300..399]
81
+ "Abstract test suite: #{title_en}"
82
+ when [400..499]
83
+ "Application module: #{title_en}"
84
+ when [500..599]
85
+ "Application interpreted construct: #{title_en}"
86
+ when [1000..1799]
87
+ "Application module: #{title_en}"
88
+ else
89
+ title_en
90
+ end
91
+ end
92
+
93
+ def full_title
94
+ "Industrial automation systems and integration -- Product data" \
95
+ " representation and exchange -- Part #{part}: #{part_title}"
96
+ end
97
+
98
+ def anchor
99
+ docid.gsub("/", "-").gsub(" ", "_").gsub(":", "_")
100
+ end
101
+
102
+ def to_mn_adoc
103
+ if title_en
104
+ "* [[[#{anchor},#{docid}]]], _#{full_title}_"
105
+ else
106
+ "* [[[#{anchor},#{docid}]]]"
107
+ end
108
+ end
109
+ end
110
+ end
111
+ end
@@ -5,6 +5,9 @@ require "stepmod/utils/converters/express_note"
5
5
  require "stepmod/utils/converters/express_example"
6
6
  require "stepmod/utils/converters/express_figure"
7
7
  require "stepmod/utils/converters/express_table"
8
+ require "expressir"
9
+ require "expressir/express/parser"
10
+ require "pubid-iso"
8
11
 
9
12
  module Stepmod
10
13
  module Utils
@@ -17,26 +20,37 @@ module Stepmod
17
20
  @express_file = express_file
18
21
  @resource_docs_cache_file = resource_docs_cache_file
19
22
  @stepmod_dir = stepmod_dir || Dir.pwd
23
+ @added_bibdata = {}
24
+
25
+ @schema_name = Expressir::Express::Parser.from_file(express_file)
26
+ .schemas
27
+ .first
28
+ .id
20
29
  end
21
30
 
22
31
  def call
23
32
  match = File.basename(express_file).match('^(arm|mim|bom)\.exp$')
24
33
  descriptions_base = match ? "#{match.captures[0]}_descriptions.xml" : "descriptions.xml"
34
+
25
35
  descriptions_file = File.join(File.dirname(express_file),
26
36
  descriptions_base)
37
+
27
38
  output_express = File.read(express_file)
28
- resource_docs_cache = JSON.parse(File.read(resource_docs_cache_file))
39
+ converted_description = ""
40
+ base_linked = ""
29
41
 
30
42
  if File.exists?(descriptions_file)
31
43
  descriptions = Nokogiri::XML(File.read(descriptions_file)).root
32
44
  added_resource_descriptions = {}
45
+
33
46
  descriptions.xpath("ext_description").each do |description|
34
47
  # Add base resource from linked path if exists, eg "language_schema.language.wr:WR1" -> "language_schema"
35
48
  base_linked = description["linkend"].to_s.split(".").first
49
+
36
50
  if added_resource_descriptions[base_linked].nil?
37
51
  base_reource_doc_dir = resource_docs_cache[description["linkend"].to_s.split(".").first]
38
52
  if base_reource_doc_dir
39
- output_express << convert_from_resource_file(
53
+ converted_description << convert_from_resource_file(
40
54
  base_reource_doc_dir, stepmod_dir, base_linked, descriptions_file
41
55
  )
42
56
  end
@@ -47,7 +61,7 @@ module Stepmod
47
61
  # when a schema description is available from resource.xml and also descriptions.xml, the description from resource.xml is only used.
48
62
  # https://github.com/metanorma/annotated-express/issues/32#issuecomment-792609078
49
63
  if description.text.strip.length.positive? && resource_docs_dir.nil?
50
- output_express << convert_from_description_text(
64
+ converted_description << convert_from_description_text(
51
65
  descriptions_file, description
52
66
  )
53
67
  end
@@ -60,7 +74,28 @@ module Stepmod
60
74
  end
61
75
  end
62
76
 
63
- output_express
77
+ bib_file_name = extract_bib_file_name(match, resource_docs_cache[@schema_name || ""])
78
+ bib_file = if match
79
+ File.join(File.dirname(express_file), bib_file_name)
80
+ else
81
+ resource_docs_file_path(stepmod_dir, bib_file_name)
82
+ end
83
+
84
+ output_express << if bib_file && File.exists?(bib_file)
85
+ prepend_bibdata(
86
+ converted_description || "",
87
+ # bib_file will not be present for resouces
88
+ # that are not in resource_docs cache.
89
+ # e.g hierarchy_schema
90
+ bib_file,
91
+ @schema_name,
92
+ match,
93
+ )
94
+ else
95
+ converted_description
96
+ end
97
+
98
+ sanitize(output_express)
64
99
  rescue StandardError => e
65
100
  puts "[ERROR]!!! #{e.message}"
66
101
  puts e.backtrace
@@ -68,6 +103,14 @@ module Stepmod
68
103
 
69
104
  private
70
105
 
106
+ def sanitize(file_content)
107
+ file_content.gsub("(*)", "(`*`)")
108
+ end
109
+
110
+ def resource_docs_cache
111
+ @resource_docs_cache ||= JSON.parse(File.read(resource_docs_cache_file))
112
+ end
113
+
71
114
  def convert_from_description_text(descriptions_file, description)
72
115
  Dir.chdir(File.dirname(descriptions_file)) do
73
116
  wrapper = "<ext_descriptions>#{description}</ext_descriptions>"
@@ -119,10 +162,146 @@ module Stepmod
119
162
  end
120
163
  end
121
164
 
165
+ def prepend_bibdata(description, bibdata_file, schema_and_entity, match)
166
+ bib = Nokogiri::XML(File.read(bibdata_file)).root
167
+ bibdata = extract_bib_data(match, bib, schema_and_entity)
168
+
169
+ return description.to_s if @added_bibdata[schema_and_entity]
170
+
171
+ published_in = <<~PUBLISHED_IN
172
+
173
+ (*"#{schema_and_entity}.__published_in"
174
+ #{bibdata[:identifier]}
175
+ *)
176
+ PUBLISHED_IN
177
+
178
+ identifier = <<~IDENTIFIER if bibdata[:number]
179
+ (*"#{schema_and_entity}.__identifier"
180
+ ISO/TC 184/SC 4/WG 12 N#{bibdata[:number]}
181
+ *)
182
+ IDENTIFIER
183
+
184
+ supersedes = <<~SUPERSEDES if bibdata[:supersedes_concept]
185
+ (*"#{schema_and_entity}.__supersedes"
186
+ ISO/TC 184/SC 4/WG 12 N#{bibdata[:supersedes_concept]}
187
+ *)
188
+ SUPERSEDES
189
+
190
+ status = <<~STATUS if bibdata[:status]
191
+ (*"#{schema_and_entity}.__status"
192
+ #{bibdata[:status]}
193
+ *)
194
+ STATUS
195
+
196
+ title = <<~TITLE if bibdata[:title]
197
+ (*"#{schema_and_entity}.__title"
198
+ #{bibdata[:title]}
199
+ *)
200
+ TITLE
201
+
202
+ document = <<~DOCUMENT if bibdata_file
203
+ (*"#{schema_and_entity}.__schema_file"
204
+ #{Pathname(bibdata_file).relative_path_from(@stepmod_dir)}
205
+ *)
206
+ DOCUMENT
207
+
208
+ @added_bibdata[schema_and_entity] = true
209
+
210
+ [
211
+ published_in,
212
+ identifier,
213
+ supersedes,
214
+ status,
215
+ title,
216
+ description,
217
+ document,
218
+ ].compact.join("\n")
219
+ end
220
+
221
+ def module?(match)
222
+ match && %w[arm mim].include?(match.captures[0])
223
+ end
224
+
225
+ def bom?(match)
226
+ match && %w[bom].include?(match.captures[0])
227
+ end
228
+
229
+ def extract_bib_file_name(match, default_file_name = "")
230
+ return default_file_name || "" unless match
231
+
232
+ if %w[arm mim].include?(match.captures[0])
233
+ "module.xml"
234
+ else
235
+ "business_object_model.xml"
236
+ end
237
+ end
238
+
239
+ def extract_bib_data(match, bib, schema_and_entity)
240
+ return resource_bib_data(bib, schema_and_entity) unless match
241
+
242
+ if module?(match)
243
+ module_bib_data(bib, match.captures[0])
244
+ elsif bom?(match)
245
+ bom_bib_data(bib)
246
+ end
247
+ end
248
+
249
+ def identifier(bib)
250
+ part = bib.attributes["part"].value
251
+ year = bib.attributes["publication.year"].value
252
+
253
+ # year="tbd" in data/modules/geometric_tolerance/module.xml and
254
+ # probabaly in some other places as well
255
+ year = "" if year == "tbd"
256
+ edition = bib.attributes["version"].value
257
+
258
+ pubid = Pubid::Iso::Identifier.new(
259
+ publisher: "ISO",
260
+ number: 10303,
261
+ )
262
+
263
+ pubid.part = part if part && !part.empty?
264
+ pubid.year = year.split("-").first if year && !year.empty?
265
+ pubid.edition = edition if edition && !edition.empty?
266
+
267
+ pubid.to_s(with_edition: true)
268
+ end
269
+
270
+ def resource_bib_data(bib, schema_and_entity)
271
+ schema = bib.xpath("schema[@name='#{schema_and_entity}']").first
272
+
273
+ {
274
+ identifier: identifier(bib),
275
+ number: schema.attributes["number"],
276
+ supersedes_concept: schema.attributes["number.supersedes"],
277
+ status: bib.attributes["status"],
278
+ title: bib.attributes["title"] || bib.attributes["name"],
279
+ }
280
+ end
281
+
282
+ def module_bib_data(bib, type)
283
+ {
284
+ identifier: identifier(bib),
285
+ number: bib.attributes["wg.number.#{type}"],
286
+ supersedes_concept: bib.attributes["wg.number.#{type}.supersedes"],
287
+ status: bib.attributes["status"],
288
+ title: bib.attributes["title"] || bib.attributes["name"],
289
+ }
290
+ end
291
+
292
+ def bom_bib_data(bib)
293
+ {
294
+ identifier: identifier(bib),
295
+ number: bib.attributes["wg.number.bom.exp"],
296
+ supersedes_concept: bib.attributes["wg.number.bom.supersedes"],
297
+ status: bib.attributes["status"],
298
+ title: bib.attributes["title"] || bib.attributes["name"],
299
+ }
300
+ end
301
+
122
302
  def convert_from_resource_file(resource_docs_dir, stepmod_dir, linked, descriptions_file)
123
- resource_docs_file = File.join(stepmod_dir, "data/resource_docs",
124
- resource_docs_dir, "resource.xml")
125
- # puts(resource_docs_file)
303
+ resource_docs_file = resource_docs_file_path(stepmod_dir, resource_docs_dir)
304
+
126
305
  resource_docs = Nokogiri::XML(File.read(resource_docs_file)).root
127
306
  schema = resource_docs.xpath("schema[@name='#{linked}']")
128
307
 
@@ -133,11 +312,20 @@ module Stepmod
133
312
  wrapper,
134
313
  {
135
314
  no_notes_examples: false,
136
- schema_and_entity: linked
137
- }
315
+ schema_and_entity: linked,
316
+ },
138
317
  )
139
318
  end
140
319
  end
320
+
321
+ def resource_docs_file_path(stepmod_dir, resource_docs_dir)
322
+ File.join(
323
+ stepmod_dir,
324
+ "data/resource_docs",
325
+ resource_docs_dir,
326
+ "resource.xml",
327
+ )
328
+ end
141
329
  end
142
330
  end
143
331
  end
@@ -7,9 +7,9 @@ module Stepmod
7
7
  attr_accessor :acronym
8
8
 
9
9
  def to_mn_adoc
10
- mn_adoc = ["=== #{definition}"]
10
+ mn_adoc = ["=== #{definition.map(&:content).join}"]
11
11
  mn_adoc << "\nalt:[#{acronym}]" if acronym
12
- mn_adoc << "\n\n#{designations.join(", ")}" if designations&.any?
12
+ mn_adoc << "\n\n#{designations.map(&:designation).join(", ")}" if designations&.any?
13
13
 
14
14
  mn_adoc.join
15
15
  end
@@ -18,15 +18,28 @@ module Stepmod
18
18
  def from_h(hash)
19
19
  _, definition, acronym = treat_acronym(hash["definition"])
20
20
 
21
- hash["definition"] = definition
21
+ hash["definition"] = [definition]
22
+
22
23
  hash["acronym"] = acronym.gsub(/\(|\)/, "") if acronym
23
- hash["designations"] = hash["synonyms"]
24
+ add_designations(hash, hash["synonyms"]) if hash["synonyms"]
24
25
 
25
- super(hash.reject { |k, _| k == "synonyms" })
26
+ new(hash.reject { |k, _| k == "synonyms" })
26
27
  end
27
28
 
28
29
  private
29
30
 
31
+ def add_designations(hash, synonyms)
32
+ hash["designations"] ||= []
33
+ hash["designations"] << designation_hash(synonyms) if synonyms
34
+ end
35
+
36
+ def designation_hash(value, type = "expression")
37
+ {
38
+ "designation" => value,
39
+ "type" => type,
40
+ }
41
+ end
42
+
30
43
  def treat_acronym(term_def)
31
44
  return [nil, term_def.strip, nil] unless term_def.match?(/.+\(.+?\)$/)
32
45