-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgenerator.rb
72 lines (59 loc) · 1.96 KB
/
generator.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
62
63
64
65
66
67
68
69
70
71
72
require_relative 'blueprint_builder'
require_relative 'testscript_builder'
# This is the generic generator class. Right now, it really only covers
# containing the different pieces (blueprint builder, testscript builder) in
# one place, as well as outputting and storing. A lot of this code is repeated
# from the testscript_generator.rb file, which should be the case until the
# generator that is currently baked into that file (interaction conformance) is
# extracted into its own class.
class Generator
attr_accessor :ig, :ig_name, :output_path
def blueprinter
@blueprinter ||= BlueprintBuilder.new
end
def script_builder
@script_builder ||= TestScriptBuilder.new
end
def blueprints
@blueprints ||= {}
end
def scripts
@scripts ||= {}
end
def initialize(output_path, ig_contents)
self.ig = ig_contents
self.output_path = "#{output_path}/search_params"
end
def make_directory(dir_name)
FileUtils.mkdir_p(dir_name)
end
def output_script(path, script, name)
File.write("#{path}/#{name}.json", script)
end
def output_example(path, resource)
example_resource = "FHIR::#{resource}".constantize.new.to_json
FileUtils.mkdir_p("#{path}/fixtures")
File.write("#{path}/fixtures/example_#{resource.downcase}.json", example_resource)
end
def build_name(*input)
input.map(&:downcase).join(" ").gsub("-", " ")
end
def assign_script_details(script, script_name)
add_boilerplate(script)
customize_script(script, script_name)
end
def add_boilerplate(script)
script.url = 'https://github.com/fhir-crucible/testscript-generator'
script.version = '0.0'
script.experimental = true
script.status = 'draft'
script.publisher = 'The MITRE Corporation'
end
def customize_script(script, script_name)
name = script_name.split(' ').map(&:capitalize)
script.name = name.join('_')
script.title = script_name
script.id = name.join('-')
script.date = DateTime.now.to_s
end
end