lib/kpm/system_helpers/entropy_available.rb in kpm-0.7.2 vs lib/kpm/system_helpers/entropy_available.rb in kpm-0.8.0
- old
+ new
@@ -1,52 +1,50 @@
+# frozen_string_literal: true
+
module KPM
module SystemProxy
- module EntropyAvailable
- class << self
+ class EntropyAvailable
+ attr_reader :entropy_available, :labels
- def fetch
- entropy_available = nil
- if OS.windows?
- entropy_available = fetch_windows
- elsif OS.linux?
- entropy_available = fetch_linux
- elsif OS.mac?
- entropy_available = fetch_mac
- end
+ def initialize
+ @entropy_available = fetch
+ @labels = [{ label: :entropy },
+ { label: :value }]
+ end
- entropy_available
- end
+ private
- def get_labels
- labels = [{:label => :entropy},
- {:label => :value}]
- labels
+ def fetch
+ entropy_available = nil
+ if OS.windows?
+ entropy_available = fetch_windows
+ elsif OS.linux?
+ entropy_available = fetch_linux
+ elsif OS.mac?
+ entropy_available = fetch_mac
end
- private
- def fetch_linux
- entropy_available_data = `cat /proc/sys/kernel/random/entropy_avail 2>&1`.gsub("\n",'')
- entropy_available = get_hash(entropy_available_data)
- entropy_available
- end
+ entropy_available
+ end
- def fetch_mac
- entropy_available = get_hash('-')
- entropy_available
- end
+ def fetch_linux
+ entropy_available_data = `cat /proc/sys/kernel/random/entropy_avail 2>&1`.gsub("\n", '')
+ build_hash(entropy_available_data)
+ end
- def fetch_windows
- entropy_available = get_hash('-')
- entropy_available
- end
+ def fetch_mac
+ build_hash('-')
+ end
- def get_hash(data)
- entropy_available = Hash.new
- entropy_available['entropy_available'] = {:entropy => 'available', :value => data}
+ def fetch_windows
+ build_hash('-')
+ end
- entropy_available
- end
+ def build_hash(data)
+ entropy_available = {}
+ entropy_available['entropy_available'] = { entropy: 'available', value: data }
+ entropy_available
end
end
end
-end
\ No newline at end of file
+end