Class: DaVinciUSDrugFormularyTestKit::Generator::ReadTestGenerator
- Inherits:
-
Object
- Object
- DaVinciUSDrugFormularyTestKit::Generator::ReadTestGenerator
- Defined in:
- lib/davinci_us_drug_formulary_test_kit/generator/read_test_generator.rb
Instance Attribute Summary collapse
-
#base_output_dir ⇒ Object
Returns the value of attribute base_output_dir.
-
#group_metadata ⇒ Object
Returns the value of attribute group_metadata.
Class Method Summary collapse
Instance Method Summary collapse
- #base_output_file_name ⇒ Object
- #class_name ⇒ Object
- #conformance_expectation ⇒ Object
- #generate ⇒ Object
-
#initialize(group_metadata, base_output_dir) ⇒ ReadTestGenerator
constructor
A new instance of ReadTestGenerator.
- #module_name ⇒ Object
- #output ⇒ Object
- #output_file_directory ⇒ Object
- #output_file_name ⇒ Object
- #profile_identifier ⇒ Object
- #read_interaction ⇒ Object
- #resource_collection_string ⇒ Object
- #resource_type ⇒ Object
- #template ⇒ Object
- #test_id ⇒ Object
Constructor Details
#initialize(group_metadata, base_output_dir) ⇒ ReadTestGenerator
Returns a new instance of ReadTestGenerator.
20 21 22 23 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/read_test_generator.rb', line 20 def initialize(, base_output_dir) self. = self.base_output_dir = base_output_dir end |
Instance Attribute Details
#base_output_dir ⇒ Object
Returns the value of attribute base_output_dir.
18 19 20 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/read_test_generator.rb', line 18 def base_output_dir @base_output_dir end |
#group_metadata ⇒ Object
Returns the value of attribute group_metadata.
18 19 20 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/read_test_generator.rb', line 18 def @group_metadata end |
Class Method Details
.generate(ig_metadata, base_output_dir) ⇒ Object
7 8 9 10 11 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/read_test_generator.rb', line 7 def generate(, base_output_dir) .groups .select { |group| read_interaction(group).present? } .each { |group| new(group, base_output_dir).generate } end |
.read_interaction(group_metadata) ⇒ Object
13 14 15 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/read_test_generator.rb', line 13 def read_interaction() .interactions.find { |interaction| interaction[:code] == 'read' } end |
Instance Method Details
#base_output_file_name ⇒ Object
33 34 35 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/read_test_generator.rb', line 33 def base_output_file_name "#{class_name.underscore}.rb" end |
#class_name ⇒ Object
57 58 59 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/read_test_generator.rb', line 57 def class_name "#{Naming.upper_camel_case_for_profile()}ReadTest" end |
#conformance_expectation ⇒ Object
77 78 79 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/read_test_generator.rb', line 77 def conformance_expectation read_interaction[:expectation] end |
#generate ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/read_test_generator.rb', line 81 def generate FileUtils.mkdir_p(output_file_directory) File.write(output_file_name, output) .add_test( id: test_id, file_name: base_output_file_name ) end |
#module_name ⇒ Object
61 62 63 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/read_test_generator.rb', line 61 def module_name "USDF#{.reformatted_version.upcase}" end |
#output ⇒ Object
29 30 31 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/read_test_generator.rb', line 29 def output @output ||= ERB.new(template).result(binding) end |
#output_file_directory ⇒ Object
37 38 39 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/read_test_generator.rb', line 37 def output_file_directory File.join(base_output_dir, profile_identifier) end |
#output_file_name ⇒ Object
41 42 43 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/read_test_generator.rb', line 41 def output_file_name File.join(output_file_directory, base_output_file_name) end |
#profile_identifier ⇒ Object
49 50 51 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/read_test_generator.rb', line 49 def profile_identifier Naming.snake_case_for_profile() end |
#read_interaction ⇒ Object
45 46 47 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/read_test_generator.rb', line 45 def read_interaction self.class.read_interaction() end |
#resource_collection_string ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/read_test_generator.rb', line 69 def resource_collection_string if .delayed? && resource_type != 'Provenance' "scratch.dig(:references, '#{resource_type}')" else 'all_scratch_resources' end end |
#resource_type ⇒ Object
65 66 67 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/read_test_generator.rb', line 65 def resource_type .resource end |
#template ⇒ Object
25 26 27 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/read_test_generator.rb', line 25 def template @template ||= File.read(File.join(__dir__, 'templates', 'read.rb.erb')) end |
#test_id ⇒ Object
53 54 55 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/read_test_generator.rb', line 53 def test_id "usdf_#{.reformatted_version}_#{profile_identifier}_read_test" end |