Module: Amnesia::Helpers::HelperMethods
- Defined in:
- lib/amnesia/helpers.rb
Constant Summary collapse
- SIZE_UNITS =
%w[ Bytes KB MB GB TB PB EB ]
Instance Method Summary collapse
- #alive_hosts ⇒ Object
- #graph_url(*data) ⇒ Object
- #number_to_human_size(number, precision = 1) ⇒ Object
Instance Method Details
#alive_hosts ⇒ Object
31 32 33 |
# File 'lib/amnesia/helpers.rb', line 31 def alive_hosts @alive_hosts ||= @hosts.select(&:alive?) end |
#graph_url(*data) ⇒ Object
12 13 14 |
# File 'lib/amnesia/helpers.rb', line 12 def graph_url(*data) Gchart.pie(data: data, size: '115x115', bg: 'ffffff00') end |
#number_to_human_size(number, precision = 1) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/amnesia/helpers.rb', line 17 def number_to_human_size(number, precision=1) number, base = Float(number), 1024 if number.to_i < base "%d %s" % [ number.to_i, SIZE_UNITS.first ] else max = SIZE_UNITS.size - 1 exp = (Math.log(number) / Math.log(base)).to_i exp = max if exp > max # avoid overflow for the highest unit result = number / (base**exp) "%.#{precision}f %s" % [ result, SIZE_UNITS[exp] ] end end |