Module: AmdgpuFan::CliOutputFormat
- Included in:
- Cli
- Defined in:
- lib/amdgpu_fan/mixin/cli_output_format.rb
Overview
A mixin to help with CLI output formatting
Constant Summary collapse
- METER_CHARS =
[' ', *("\u2588".."\u258F").to_a.reverse].freeze
- TIME_FORMAT =
'%F %T'
Instance Method Summary collapse
- #current_time ⇒ Object
-
#percent_meter(percent, width = 3) ⇒ Object
Return a string with meter and percentage for
percent. - #radeon_logo ⇒ Object
Instance Method Details
#current_time ⇒ Object
9 10 11 |
# File 'lib/amdgpu_fan/mixin/cli_output_format.rb', line 9 def current_time Time.now.strftime(TIME_FORMAT) end |
#percent_meter(percent, width = 3) ⇒ Object
Return a string with meter and percentage for percent
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/amdgpu_fan/mixin/cli_output_format.rb', line 16 def percent_meter(percent, width = 3) meter_char_indexes = [] percent_portion_size = 100.0 / width width.times do |i| current_portion = percent.to_i - (percent_portion_size * i) current_portion_percent = if current_portion >= percent_portion_size 1 elsif current_portion <= 0 0 else current_portion / percent_portion_size end meter_char_indexes << ((METER_CHARS.length - 1) * current_portion_percent.to_f).round end percent_string = "#{format '%<num>0.2i', num: percent}%".ljust(4) "#{percent_string}[#{meter_char_indexes.map { |i| METER_CHARS[i] }.join}]" end |
#radeon_logo ⇒ Object
37 38 39 |
# File 'lib/amdgpu_fan/mixin/cli_output_format.rb', line 37 def radeon_logo File.read(File.join(__dir__, '../../../assets/radeon_r_black_red_100x100.ascii')) end |