Class: PacioInfernoCore::Generator::IGLoader
- Inherits:
-
Object
- Object
- PacioInfernoCore::Generator::IGLoader
- Defined in:
- lib/pacio_inferno_core/generator/ig_loader.rb
Instance Attribute Summary collapse
-
#ig_file_name ⇒ Object
Returns the value of attribute ig_file_name.
Instance Method Summary collapse
- #ig_resources ⇒ Object
-
#initialize(ig_file_name) ⇒ IGLoader
constructor
A new instance of IGLoader.
- #load ⇒ Object
- #load_ig ⇒ Object
- #load_standalone_resources ⇒ Object
Constructor Details
#initialize(ig_file_name) ⇒ IGLoader
Returns a new instance of IGLoader.
13 14 15 |
# File 'lib/pacio_inferno_core/generator/ig_loader.rb', line 13 def initialize(ig_file_name) self.ig_file_name = ig_file_name end |
Instance Attribute Details
#ig_file_name ⇒ Object
Returns the value of attribute ig_file_name.
11 12 13 |
# File 'lib/pacio_inferno_core/generator/ig_loader.rb', line 11 def ig_file_name @ig_file_name end |
Instance Method Details
#ig_resources ⇒ Object
17 18 19 |
# File 'lib/pacio_inferno_core/generator/ig_loader.rb', line 17 def ig_resources @ig_resources ||= IGResources.new end |
#load ⇒ Object
21 22 23 24 |
# File 'lib/pacio_inferno_core/generator/ig_loader.rb', line 21 def load load_ig load_standalone_resources end |
#load_ig ⇒ Object
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 |
# File 'lib/pacio_inferno_core/generator/ig_loader.rb', line 26 def load_ig tar = Gem::Package::TarReader.new( Zlib::GzipReader.open(ig_file_name) ) tar.each do |entry| next if entry.directory? file_name = entry.full_name.split('/').last next if file_name.end_with? 'openapi.json' 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
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/pacio_inferno_core/generator/ig_loader.rb', line 56 def load_standalone_resources ig_directory = ig_file_name.chomp('.tgz') return ig_resources unless File.exist? ig_directory Dir.glob(File.join(ig_directory, '*.{json,tgz}')).each do |file_path| if file_path.end_with? '.tgz' load_tgz_resources(file_path) else load_json_resource(file_path) end end ig_resources end |