Skip to content

Commit

Permalink
also detect XML values for option nodes; add example script
Browse files Browse the repository at this point in the history
  • Loading branch information
cooperka committed Apr 23, 2024
1 parent 139093c commit f3874ee
Showing 1 changed file with 54 additions and 2 deletions.
56 changes: 54 additions & 2 deletions lib/tasks/create_uuid_list.rake
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

UUID_FORMAT = /<((?:grp|qing|os|on)[a-z0-9\-]+)>/
KEY_ID_FORMAT = /<((?:grp|qing)[a-z0-9\-]+)>/
VALUE_ID_FORMAT = />((?:os|on)[a-z0-9\-]+)</

# Given a directory path DIR,
# save a list of every unique NEMO UUID discovered in the XML form submission files there.
Expand All @@ -17,7 +18,13 @@ task create_uuid_list: :environment do
data = File.read(f)

total = 0
data.scan(UUID_FORMAT) do |matches|
data.scan(KEY_ID_FORMAT) do |matches|
total += 1
uuid = matches[0]
ids[uuid] = true
end

data.scan(VALUE_ID_FORMAT) do |matches|
total += 1
uuid = matches[0]
ids[uuid] = true
Expand All @@ -31,3 +38,48 @@ task create_uuid_list: :environment do
puts ids.keys.sort.inspect
puts "\n#{ids.count} unique IDs."
end

=begin
require './list.rb'
UUID_FORMAT = /(grp|qing|os|on)(.+)/
table = {}
errors = []
LIST.each do |id|
puts id
id.scan(UUID_FORMAT) do |matches|
type = matches[0]
uuid = matches[1]
result = nil
case type
when "grp"
obj = FormItem.find_by(id: uuid)
result = obj ? obj.group_name || "[Blank]" : "[Nonexistent ID: #{id}]"
errors << id unless obj&.group_name.present?
when "qing"
obj = FormItem.find_by(id: uuid)
result = obj ? obj.code || "[Blank]" : "[Nonexistent ID: #{id}]"
errors << id unless obj&.code.present?
when "os"
obj = OptionSet.find_by(id: uuid)
result = obj ? obj.name || "[Blank]" : "[Nonexistent ID: #{id}]"
errors << id unless obj&.name.present?
when "on"
obj = OptionNode.find_by(id: uuid)
result = obj ? obj.name || "[Blank]" : "[Nonexistent ID: #{id}]"
errors << id unless obj&.name.present?
else
result = "[Unknown type]"
end
table[id] = result
end
end
puts "\nTable:"
puts table.to_json
puts "\nErrors:"
puts errors.inspect
=end

1

0 comments on commit f3874ee

Please sign in to comment.