-
Notifications
You must be signed in to change notification settings - Fork 495
Expand file tree
/
Copy pathsystem_profile_executor.rb
More file actions
38 lines (30 loc) · 997 Bytes
/
system_profile_executor.rb
File metadata and controls
38 lines (30 loc) · 997 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# frozen_string_literal: true
module Facter
module Resolvers
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