Class: DaVinciUSDrugFormularyTestKit::Generator::ReadTestGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/davinci_us_drug_formulary_test_kit/generator/read_test_generator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_dirObject

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_metadataObject

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_nameObject



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_nameObject



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_expectationObject



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

#generateObject



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_nameObject



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

#outputObject



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_directoryObject



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_nameObject



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_identifierObject



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_interactionObject



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_stringObject



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_typeObject



65
66
67
# File 'lib/davinci_us_drug_formulary_test_kit/generator/read_test_generator.rb', line 65

def resource_type
  .resource
end

#templateObject



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_idObject



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