@@ -88,16 +88,16 @@ def unreferenced? = !@ref_to_me
8888end
8989
9090########################################
91- # Classes for Normative Rule Curations #
91+ # Classes for Normative Rule Creations #
9292########################################
9393
94- # Holds all the information for all the normative rule curation files.
95- class NormativeCurations
96- attr_reader :normative_curations # Array<NormativeCuration > Contains all normative rules across all input files
94+ # Holds all the information for all the normative rule creation files.
95+ class NormativeRuleCreations
96+ attr_reader :norm_rule_creations # Array<NormativeRuleCreation > Contains all normative rules across all input files
9797
9898 def initialize
99- @normative_curations = [ ]
100- @hash = { } # Hash<String name, NormativeCuration > Same objects as in array and just internal to class
99+ @norm_rule_creations = [ ]
100+ @hash = { } # Hash<String name, NormativeRuleCreation > Same objects as in array and just internal to class
101101 end
102102
103103 def add_file_contents ( filename , array_data )
@@ -108,37 +108,37 @@ def add_file_contents(filename, array_data)
108108 fatal_error ( "File #{ filename } entry isn't a hash: #{ data } " ) unless data . is_a? ( Hash )
109109
110110 if !data [ "name" ] . nil?
111- # Add one curation object
112- add_curation ( data [ "name" ] , filename , data )
111+ # Add one creation object
112+ add_creation ( data [ "name" ] , filename , data )
113113 elsif !data [ "names" ] . nil?
114- # Add one curation object for each name in array
114+ # Add one creation object for each name in array
115115 names = data [ "names" ]
116116 names . each do |name |
117- add_curation ( name , filename , data )
117+ add_creation ( name , filename , data )
118118 end
119119 else
120- fatal_error ( "File #{ filename } missing name/names in normative rule curation entry: #{ data } " )
120+ fatal_error ( "File #{ filename } missing name/names in normative rule creation entry: #{ data } " )
121121 end
122122 end
123123 end
124124
125- def add_curation ( name , filename , data )
125+ def add_creation ( name , filename , data )
126126 fatal_error ( "Need String for name but passed a #{ name . class } " ) unless name . is_a? ( String )
127127 fatal_error ( "Need String for filename but passed a #{ filename . class } " ) unless filename . is_a? ( String )
128128 fatal_error ( "Need Hash for data but passed a #{ data . class } " ) unless data . is_a? ( Hash )
129129
130130 unless @hash [ name ] . nil?
131- fatal_error ( "Normative rule curation #{ name } in file #{ filename } already defined in file #{ @hash [ name ] . filename } " )
131+ fatal_error ( "Normative rule creation #{ name } in file #{ filename } already defined in file #{ @hash [ name ] . filename } " )
132132 end
133133
134- # Create curation object and store reference to it in array (to maintain order) and hash (for convenient lookup by name).
135- normative_curation = NormativeCuration . new ( filename , name , data )
136- @normative_curations . append ( normative_curation )
137- @hash [ name ] = normative_curation
134+ # Create creation object and store reference to it in array (to maintain order) and hash (for convenient lookup by name).
135+ norm_rule_creations = NormativeRuleCreation . new ( filename , name , data )
136+ @norm_rule_creations . append ( norm_rule_creations )
137+ @hash [ name ] = norm_rule_creations
138138 end
139- end # class NormativeCurations
139+ end # class NormativeRuleCreations
140140
141- class NormativeCuration
141+ class NormativeRuleCreation
142142 attr_reader :filename # String (mandatory)
143143 attr_reader :name # String (mandatory)
144144 attr_reader :type # String (optional)
@@ -164,9 +164,9 @@ def initialize(filename, name, data)
164164 @tag_refs_without_text . append ( NormativeTagRef . new ( tag_data ) )
165165 end
166166 end
167- end # class NormativeCuration
167+ end # class NormativeRuleCreation
168168
169- # Holds one reference to a tag by a curation .
169+ # Holds one reference to a tag by a creation .
170170class NormativeTagRef
171171 attr_reader :name
172172
@@ -189,10 +189,10 @@ def info(msg)
189189
190190def usage ( exit_status = 1 )
191191 puts "Usage: #{ PN } [OPTION]... <output-filename>"
192- puts " -c filename normative rule curation filename (YAML)"
192+ puts " -c filename normative rule creation filename (YAML)"
193193 puts " -t filename normative tag filename (JSON)"
194194 puts
195- puts "Creates curated list of normative rules and stores them <output-filename> (in JSON format)."
195+ puts "Creates list of normative rules and stores them in <output-filename> (in JSON format)."
196196 exit exit_status
197197end
198198
@@ -205,7 +205,7 @@ def parse_argv
205205 usage if ARGV . count == 0
206206
207207 # Return values
208- curation_fnames = [ ]
208+ creation_fnames = [ ]
209209 tag_fnames = [ ]
210210 output_fname =
211211
@@ -218,7 +218,7 @@ def parse_argv
218218 info ( "Missing argument for -c option" )
219219 usage
220220 end
221- curation_fnames . append ( ARGV [ i +1 ] )
221+ creation_fnames . append ( ARGV [ i +1 ] )
222222 i = i +1
223223 when "-t"
224224 if ( ARGV . count -i ) < 1
@@ -242,8 +242,8 @@ def parse_argv
242242 i = i +1
243243 end
244244
245- if curation_fnames . empty?
246- info ( "Missing normative rule curation filename(s)" )
245+ if creation_fnames . empty?
246+ info ( "Missing normative rule creation filename(s)" )
247247 usage
248248 end
249249
@@ -257,7 +257,7 @@ def parse_argv
257257 usage
258258 end
259259
260- return [ curation_fnames , tag_fnames , output_fname ]
260+ return [ creation_fnames , tag_fnames , output_fname ]
261261end
262262
263263# Load the contents of all normative rule tag files in JSON format.
@@ -295,15 +295,15 @@ def load_tags(tag_fnames)
295295 return tags
296296end
297297
298- # Load the contents of all normative rule curation files in YAML format.
299- # Returns a NormativeCuration class with all the contents.
300- def load_curations ( curation_fnames )
301- fatal_error ( "Need Array<String> for curation_fnames but passed a #{ curation_fnames . class } " ) unless curation_fnames . is_a? ( Array )
298+ # Load the contents of all normative rule creation files in YAML format.
299+ # Returns a NormativeRuleCreation class with all the contents.
300+ def load_creations ( creation_fnames )
301+ fatal_error ( "Need Array<String> for creation_fnames but passed a #{ creation_fnames . class } " ) unless creation_fnames . is_a? ( Array )
302302
303- curations = NormativeCurations . new ( )
303+ creations = NormativeRuleCreations . new ( )
304304
305- curation_fnames . each do |filename |
306- info ( "Loading curation file #{ filename } " )
305+ creation_fnames . each do |filename |
306+ info ( "Loading creation file #{ filename } " )
307307
308308 # Read in file to a String
309309 begin
@@ -320,52 +320,55 @@ def load_curations(curation_fnames)
320320 fatal_error ( "File #{ filename } YAML syntax error - #{ e . message } " )
321321 end
322322
323- array_data = yaml_hash [ "normative_curations " ] || fatal_error ( "Missing 'normative_curations ' key in #{ filename } " )
324- fatal_error ( "'normative_curations ' isn't an array in #{ filename } " ) unless array_data . is_a? ( Array )
323+ array_data = yaml_hash [ "normative_rule_creations " ] || fatal_error ( "Missing 'normative_rule_creations ' key in #{ filename } " )
324+ fatal_error ( "'normative_rule_creations ' isn't an array in #{ filename } " ) unless array_data . is_a? ( Array )
325325
326- curations . add_file_contents ( filename , array_data )
326+ creations . add_file_contents ( filename , array_data )
327327 end
328328
329- return curations
329+ return creations
330330end
331331
332- # Returns an Array of Hashes containing the curated normative rules ready to be serialized into a YAML file .
333- def create_curated_rules ( tags , curations )
332+ # Returns a Hash with just one entry called "normative_rules" that contains an Array of Hashes of all normative rules .
333+ def create_normative_rules ( tags , creations )
334334 fatal_error ( "Need NormativeTags for tags but was passed a #{ tags . class } " ) unless tags . is_a? ( NormativeTags )
335- fatal_error ( "Need NormativeCurations for curations but was passed a #{ curations . class } " ) unless curations . is_a? ( NormativeCurations )
335+ fatal_error ( "Need NormativeRuleCreations for creations but was passed a #{ creations . class } " ) unless creations . is_a? ( NormativeRuleCreations )
336336
337- info ( "Creating curated normative rules" )
337+ info ( "Creating created normative rules" )
338+
339+ ret = {
340+ "normative_rules" => [ ]
341+ }
338342
339- ret = [ ]
340343 missing_tag_cnt = 0
341344
342- curations . normative_curations . each do |curation |
343- # Create hash with mandatory curation arguments.
345+ creations . norm_rule_creations . each do |creation |
346+ # Create hash with mandatory creation arguments.
344347 hash = {
345- "name" => curation . name ,
346- "filename" => curation . filename
348+ "name" => creation . name ,
349+ "filename" => creation . filename
347350 }
348351
349352 # Now add optional arguments.
350- hash [ "type" ] = curation . type unless curation . type . nil?
351- hash [ "summary" ] = curation . summary unless curation . summary . nil?
352- hash [ "description" ] = curation . description unless curation . description . nil?
353+ hash [ "type" ] = creation . type unless creation . type . nil?
354+ hash [ "summary" ] = creation . summary unless creation . summary . nil?
355+ hash [ "description" ] = creation . description unless creation . description . nil?
353356
354- unless curation . tag_refs . nil? && curation . tag_refs_without_text . nil?
357+ unless creation . tag_refs . nil? && creation . tag_refs_without_text . nil?
355358 hash [ "tags" ] = [ ]
356359 end
357360
358361 # Add tag entries for those that should have tag text.
359- unless curation . tag_refs . nil?
360- curation . tag_refs . each do |tag_ref |
362+ unless creation . tag_refs . nil?
363+ creation . tag_refs . each do |tag_ref |
361364 tag_ref_name = tag_ref . name
362365
363366 # Lookup tag
364367 tag = tags . get_tag ( tag_ref_name )
365368
366369 if tag . nil?
367370 missing_tag_cnt = missing_tag_cnt + 1
368- info ( "Normative rule #{ curation . name } in file #{ curation . filename } references non-existant tag #{ tag_ref_name } " )
371+ info ( "Normative rule #{ creation . name } in file #{ creation . filename } references non-existant tag #{ tag_ref_name } " )
369372 else
370373 resolved_tag = {
371374 "tag_name" => tag . tag_name ,
@@ -382,8 +385,8 @@ def create_curated_rules(tags, curations)
382385 end
383386
384387 # Add tag entries for those that shouldn't have tag text.
385- unless curation . tag_refs_without_text . nil?
386- curation . tag_refs_without_text . each do |tag_ref |
388+ unless creation . tag_refs_without_text . nil?
389+ creation . tag_refs_without_text . each do |tag_ref |
387390 tag_ref_name = tag_ref . name
388391
389392 # Lookup tag. Should be nil.
@@ -396,13 +399,13 @@ def create_curated_rules(tags, curations)
396399
397400 hash [ "tags" ] . append ( resolved_tag )
398401 else
399- fatal_error ( "Normative rule #{ curation . name } in file #{ curation . filename } has
402+ fatal_error ( "Normative rule #{ creation . name } in file #{ creation . filename } has
400403#{ PN } : tag #{ tag_ref_name } tag text but shouldn't")
401404 end
402405 end
403406 end
404407
405- ret . append ( hash )
408+ ret [ "normative_rules" ] . append ( hash )
406409 end
407410
408411 fatal_error ( "#{ missing_tag_cnt } reference#{ missing_tag_cnt == 1 ? "" : "s" } to non-existing tags" ) if missing_tag_cnt > 0
@@ -411,11 +414,11 @@ def create_curated_rules(tags, curations)
411414end
412415
413416# Report any tags not referenced by any normative rule.
414- # Must be called after curated_rules are created so pass them in
417+ # Must be called after normative_rules are created so pass them in
415418# to this method but don't use them.
416- def detect_unreferenced_tags ( tags , curated_rules )
419+ def detect_unreferenced_tags ( tags , normative_rules )
417420 fatal_error ( "Need NormativeTags for tags but was passed a #{ tags . class } " ) unless tags . is_a? ( NormativeTags )
418- fatal_error ( "Need Array< Hash> for curated_rules but passed a #{ curated_rules . class } " ) unless curated_rules . is_a? ( Array )
421+ fatal_error ( "Need Hash<String, Array > for normative_rules but passed a #{ normative_rules . class } " ) unless normative_rules . is_a? ( Hash )
419422
420423 unref_cnt = 0
421424
@@ -430,16 +433,19 @@ def detect_unreferenced_tags(tags, curated_rules)
430433 info ( "#{ unref_cnt } tag#{ unref_cnt == 1 ? "" : "s" } have no normative rules referencing them" ) if unref_cnt > 0
431434end
432435
433- # Store curated rules in JSON output file
434- def store_curated_rules ( filename , curated_rules )
436+ # Store normative rules in JSON output file
437+ def store_normative_rules ( filename , normative_rules )
435438 fatal_error ( "Need String for filename but passed a #{ filename . class } " ) unless filename . is_a? ( String )
436- fatal_error ( "Need Array<Hash> for curated_rules but passed a #{ curated_rules . class } " ) unless curated_rules . is_a? ( Array )
439+ fatal_error ( "Need Hash<String, Array> for normative_rules but passed a #{ normative_rules . class } " ) unless normative_rules . is_a? ( Hash )
440+
441+ nr_array = normative_rules [ "normative_rules" ]
442+ raise "Expecting an array for key normative_rules but got an #{ nr_array . class } " unless nr_array . is_a? ( Array )
437443
438- info ( "Storing #{ curated_rules . count } curated normative rules into file #{ filename } " )
444+ info ( "Storing #{ nr_array . count } created normative rules into file #{ filename } " )
439445
440- # Serialize curated_rules Array to JSON format String.
446+ # Serialize normative_rules hash to JSON format String.
441447 # Shouldn't throw exceptions since we created the data being serialized.
442- serialized_string = JSON . pretty_generate ( curated_rules )
448+ serialized_string = JSON . pretty_generate ( normative_rules )
443449
444450 # Write serialized string to desired output file.
445451 begin
@@ -459,16 +465,16 @@ def store_curated_rules(filename, curated_rules)
459465
460466info ( "Passed #{ ARGV . join ( ' ' ) } " )
461467
462- curation_fnames , tag_fnames , output_fname = parse_argv ( )
468+ creation_fnames , tag_fnames , output_fname = parse_argv ( )
463469
464- info ( "Normative rule curation filenames = #{ curation_fnames } " )
470+ info ( "Normative rule creation filenames = #{ creation_fnames } " )
465471info ( "Normative tag filenames = #{ tag_fnames } " )
466472info ( "Output filename = #{ output_fname } " )
467473
468474tags = load_tags ( tag_fnames )
469- curations = load_curations ( curation_fnames )
470- curated_rules = create_curated_rules ( tags , curations )
471- detect_unreferenced_tags ( tags , curated_rules )
472- store_curated_rules ( output_fname , curated_rules )
475+ creations = load_creations ( creation_fnames )
476+ normative_rules = create_normative_rules ( tags , creations )
477+ detect_unreferenced_tags ( tags , normative_rules )
478+ store_normative_rules ( output_fname , normative_rules )
473479
474480exit 0
0 commit comments