class Object
Public Instance Methods
human_decimal_size(n)
click to toggle source
@param n [Numeric] number @return [String] such as 3.14M, 234E @example
human_decimal_size(1000) #=> "1.0M"
# File lib/anthroposi.rb, line 82 def human_decimal_size(n) Anthroposi.new(n, true).to_s end
human_size(b)
click to toggle source
wrapper function around Anthroposi
class @param b [Integer] bytes @return [String] such as 3.14MiB, 234EiB @example
human_size(1024) #=> "1.0KiB"
# File lib/anthroposi.rb, line 74 def human_size(b) Anthroposi.new(b).to_s end
significant_digits(number, digits)
click to toggle source
helper method to compute a number to a given number of significant digits @param number [Numeric] @param digits [Integer] number of significant digits desired @return [Numeric] @example
significant_digits(116_067, 2) #=> 120000
# File lib/anthroposi.rb, line 64 def significant_digits(number, digits) return 0 if number.zero? || digits.zero? number.to_f.round(digits - 1 - Math.log10(number.abs).floor) end