Class: Measures::MATMeasureFiles

Inherits:
Object
  • Object
show all
Defined in:
lib/measure-loader/mat_measure_files.rb

Defined Under Namespace

Classes: CqlLibraryFiles

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hqmf_xml, cql_libraries, human_readable) ⇒ MATMeasureFiles

Returns a new instance of MATMeasureFiles.



18
19
20
21
22
23
24
25
26
# File 'lib/measure-loader/mat_measure_files.rb', line 18

def initialize(hqmf_xml, cql_libraries, human_readable)
  @hqmf_xml = hqmf_xml
  @cql_libraries = cql_libraries
  @human_readable = human_readable

  raise MeasureLoadingInvalidPackageException.new("Measure package missing required element: HQMF XML File") if @hqmf_xml.nil?
  raise MeasureLoadingInvalidPackageException.new("Measure package missing required element: Human Readable Document") if @human_readable.nil?
  raise MeasureLoadingInvalidPackageException.new("Measure package missing required element: CQL Libraries") if @cql_libraries.nil? || @cql_libraries.empty?
end

Instance Attribute Details

#componentsObject

Returns the value of attribute components.



5
6
7
# File 'lib/measure-loader/mat_measure_files.rb', line 5

def components
  @components
end

#cql_librariesObject

Returns the value of attribute cql_libraries.



5
6
7
# File 'lib/measure-loader/mat_measure_files.rb', line 5

def cql_libraries
  @cql_libraries
end

#hqmf_xmlObject

Returns the value of attribute hqmf_xml.



5
6
7
# File 'lib/measure-loader/mat_measure_files.rb', line 5

def hqmf_xml
  @hqmf_xml
end

#human_readableObject

Returns the value of attribute human_readable.



5
6
7
# File 'lib/measure-loader/mat_measure_files.rb', line 5

def human_readable
  @human_readable
end

Class Method Details

.create_from_zip_file(zip_file) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/measure-loader/mat_measure_files.rb', line 28

def self.create_from_zip_file(zip_file)
  folders = unzip_measure_zip_into_hash(zip_file).values
  raise MeasureLoadingInvalidPackageException.new("No measure found") if folders.empty?
  folders.sort_by! { |h| h[:depth] }
  raise MeasureLoadingInvalidPackageException.new("Multiple measure folders at top level") if folders[0][:depth] == folders.dig(1,:depth)

  measure_folder, *component_measure_folders = folders
  measure_assets = make_measure_artifacts(parse_measure_files(measure_folder))
  measure_assets.components = component_measure_folders.collect {|f| make_measure_artifacts(parse_measure_files(f))}

  return measure_assets
rescue StandardError => e
  raise MeasureLoadingInvalidPackageException.new("Error processing package file: #{e.message}")
end

.valid_zip?(zip_file) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
46
47
48
# File 'lib/measure-loader/mat_measure_files.rb', line 43

def self.valid_zip?(zip_file)
  create_from_zip_file(zip_file)
  return true
rescue MeasureLoadingInvalidPackageException
  return false
end