Sha256: 078d80c7667a1848c88eea8f08bdd4777ab8065b9f50d777e41ca6b7cc63d561

Contents?: true

Size: 1.76 KB

Versions: 17

Compression:

Stored size: 1.76 KB

Contents

module Inferno
  module Utils
    module IgDownloader
      FHIR_PACKAGE_NAME_REG_EX = /^[a-z][a-zA-Z0-9-]*\.([a-z][a-zA-Z0-9-]*\.?)*/
      HTTP_URI_REG_EX = %r{^https?://[^/?#]+[^?#]*}
      FILE_URI_REG_EX = %r{^file://(.+)}
      HTTP_URI_END_REG_EX = %r{[^/]*\.x?html?$}

      def ig_path
        File.join('lib', library_name, 'igs')
      end

      def ig_file(suffix = nil)
        File.join(ig_path, suffix ? "package_#{suffix}.tgz" : 'package.tgz')
      end

      def load_ig(ig_input, idx = nil, thor_config = { verbose: true })
        case ig_input
        when FHIR_PACKAGE_NAME_REG_EX
          uri = ig_registry_url(ig_input)
        when HTTP_URI_REG_EX
          uri = ig_http_url(ig_input)
        when FILE_URI_REG_EX
          uri = ig_input[7..]
        else
          raise StandardError, <<~FAILED_TO_LOAD
            Could not find implementation guide: #{ig_input}
            Put its package.tgz file directly in #{ig_path}
          FAILED_TO_LOAD
        end

        # use Thor's get to support CLI options config
        get(uri, ig_file(idx), thor_config)
        uri
      end

      def ig_registry_url(ig_npm_style)
        unless ig_npm_style.include? '@'
          raise StandardError, <<~NO_VERSION
            No IG version specified for #{ig_npm_style}; you must specify one with '@'. I.e: hl7.fhir.us.core@6.1.0
          NO_VERSION
        end

        package_name, version = ig_npm_style.split('@')
        "https://packages.fhir.org/#{package_name}/-/#{package_name}-#{version}.tgz"
      end

      def ig_http_url(ig_page_url)
        return ig_page_url if ig_page_url.end_with? 'package.tgz'

        return "#{ig_page_url}package.tgz" if ig_page_url.end_with? '/'

        ig_page_url.gsub(HTTP_URI_END_REG_EX, 'package.tgz')
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
inferno_core-0.5.3 lib/inferno/utils/ig_downloader.rb
inferno_core-0.5.2 lib/inferno/utils/ig_downloader.rb
inferno_core-0.5.1 lib/inferno/utils/ig_downloader.rb
inferno_core-0.5.0 lib/inferno/utils/ig_downloader.rb
inferno_core-0.4.44 lib/inferno/utils/ig_downloader.rb
inferno_core-0.4.43 lib/inferno/utils/ig_downloader.rb
inferno_core-0.4.42 lib/inferno/utils/ig_downloader.rb
inferno_core-0.4.41 lib/inferno/utils/ig_downloader.rb
inferno_core-0.4.40 lib/inferno/utils/ig_downloader.rb
inferno_core-0.4.39 lib/inferno/utils/ig_downloader.rb
inferno_core-0.4.38 lib/inferno/utils/ig_downloader.rb
inferno_core-0.4.35 lib/inferno/utils/ig_downloader.rb
inferno_core-0.4.34 lib/inferno/utils/ig_downloader.rb
inferno_core-0.4.33 lib/inferno/utils/ig_downloader.rb
inferno_core-0.4.32 lib/inferno/utils/ig_downloader.rb
inferno_core-0.4.31 lib/inferno/utils/ig_downloader.rb
inferno_core-0.4.30 lib/inferno/utils/ig_downloader.rb