class Facter::Util::Macosx::SystemProfileExecutor

Public Class Methods

execute(category_name) click to toggle source
# File lib/facter/util/macosx/system_profile_executor.rb, line 10
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 Class Methods

normalize_keys(system_profiler_hash) click to toggle source
# File lib/facter/util/macosx/system_profile_executor.rb, line 29
def normalize_keys(system_profiler_hash)
  system_profiler_hash.map do |k, v|
    [k.downcase.tr(' ', '_').delete("\(\)").to_sym, v]
  end.to_h
end
output_to_hash(output) click to toggle source
# File lib/facter/util/macosx/system_profile_executor.rb, line 25
def output_to_hash(output)
  output.scan(/.*:[ ].*$/).map { |e| e.strip.match(/(.*?): (.*)/).captures }.to_h
end