Class: USCoreTestKit::Generator::IGLoader
- Inherits:
-
Object
- Object
- USCoreTestKit::Generator::IGLoader
- Defined in:
- lib/us_core_test_kit/generator/ig_loader.rb
Instance Attribute Summary collapse
-
#base_ig_directory ⇒ Object
Returns the value of attribute base_ig_directory.
Instance Method Summary collapse
- #ig_resources ⇒ Object
-
#initialize(base_ig_directory) ⇒ IGLoader
constructor
A new instance of IGLoader.
- #load ⇒ Object
- #load_ig ⇒ Object
- #load_standalone_resources ⇒ Object
Constructor Details
#initialize(base_ig_directory) ⇒ IGLoader
Returns a new instance of IGLoader.
12 13 14 |
# File 'lib/us_core_test_kit/generator/ig_loader.rb', line 12 def initialize(base_ig_directory) self.base_ig_directory = base_ig_directory end |
Instance Attribute Details
#base_ig_directory ⇒ Object
Returns the value of attribute base_ig_directory.
10 11 12 |
# File 'lib/us_core_test_kit/generator/ig_loader.rb', line 10 def base_ig_directory @base_ig_directory end |
Instance Method Details
#ig_resources ⇒ Object
16 17 18 |
# File 'lib/us_core_test_kit/generator/ig_loader.rb', line 16 def ig_resources @ig_resources ||= IGResources.new end |
#load ⇒ Object
20 21 22 23 |
# File 'lib/us_core_test_kit/generator/ig_loader.rb', line 20 def load load_ig load_standalone_resources end |
#load_ig ⇒ Object
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 |
# File 'lib/us_core_test_kit/generator/ig_loader.rb', line 25 def load_ig tar = Gem::Package::TarReader.new(Zlib::GzipReader.open(File.join(base_ig_directory, 'package.tgz'))) tar.each do |entry| next if entry.directory? file_name = entry.full_name.split('/').last next unless file_name.end_with? '.json' next unless entry.full_name.start_with? 'package/' begin resource = FHIR.from_contents(entry.read) next if resource.nil? rescue StandardError puts "#{file_name} does not appear to be a FHIR resource." next end ig_resources.add(resource) end ig_resources end |
#load_standalone_resources ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/us_core_test_kit/generator/ig_loader.rb', line 51 def load_standalone_resources Dir.glob(File.join(base_ig_directory, '*.json')).each do |file_path| begin resource = FHIR.from_contents(File.read(file_path)) next if resource.nil? rescue StandardError file_name = file_path.split('/').last puts "#{file_name} does not appear to be a FHIR resource." next end ig_resources.add(resource) end ig_resources end |