Sha256: b586961effb4d7799948cc78a5fa86750bee24fb32c9dbcbf63b23189dfb7430

Contents?: true

Size: 992 Bytes

Versions: 32

Compression:

Stored size: 992 Bytes

Contents

# frozen_string_literal: true

module Facter
  module Util
    module Macosx
      class SystemProfileExecutor
        @log = Log.new(self)

        class << self
          def execute(category_name)
            @log.debug "Executing command: system_profiler #{category_name}"
            output = Facter::Core::Execution.execute(
              "system_profiler #{category_name}", logger: @log
            )&.force_encoding('UTF-8')

            return unless output

            system_profiler_hash = output_to_hash(output)

            normalize_keys(system_profiler_hash)
          end

          private

          def output_to_hash(output)
            output.scan(/.*:[ ].*$/).map { |e| e.strip.match(/(.*?): (.*)/).captures }.to_h
          end

          def normalize_keys(system_profiler_hash)
            system_profiler_hash.map do |k, v|
              [k.downcase.tr(' ', '_').delete("\(\)").to_sym, v]
            end.to_h
          end
        end
      end
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
facter-4.5.2 lib/facter/util/macosx/system_profile_executor.rb
facter-4.5.1 lib/facter/util/macosx/system_profile_executor.rb
facter-4.5.0 lib/facter/util/macosx/system_profile_executor.rb
facter-4.4.3 lib/facter/util/macosx/system_profile_executor.rb
facter-4.4.2 lib/facter/util/macosx/system_profile_executor.rb
facter-4.4.1 lib/facter/util/macosx/system_profile_executor.rb
facter-4.4.0 lib/facter/util/macosx/system_profile_executor.rb
facter-4.3.1 lib/facter/util/macosx/system_profile_executor.rb
facter-4.3.0 lib/facter/util/macosx/system_profile_executor.rb
facter-4.2.14 lib/facter/util/macosx/system_profile_executor.rb
facter-4.2.13 lib/facter/util/macosx/system_profile_executor.rb
facter-4.2.12 lib/facter/util/macosx/system_profile_executor.rb
facter-4.2.11 lib/facter/util/macosx/system_profile_executor.rb
facter-4.2.10 lib/facter/util/macosx/system_profile_executor.rb
facter-4.2.9 lib/facter/util/macosx/system_profile_executor.rb
facter-4.2.8 lib/facter/util/macosx/system_profile_executor.rb
facter-4.2.7 lib/facter/util/macosx/system_profile_executor.rb
facter-4.2.6 lib/facter/util/macosx/system_profile_executor.rb
facter-4.2.5 lib/facter/util/macosx/system_profile_executor.rb
facter-4.2.4 lib/facter/util/macosx/system_profile_executor.rb