class Humr::Handler::SIPrefix
Constants
- PREFIXES
Public Instance Methods
base()
click to toggle source
# File lib/humr/handler/si_prefix.rb, line 9 def base 1000 end
replace(s) { |format % [ n, PREFIXES| ... }
click to toggle source
# File lib/humr/handler/si_prefix.rb, line 13 def replace(s, &block) if /^\d{4,}$/ === s s.gsub(/(\d{4,})/) do |size| n = size.to_f i = 0 while n >= base and i < PREFIXES.length - 1 n = n / base i = i + 1 end format = if n < 10 '%.1f%s' else '%d%s' end yield format % [ n, PREFIXES[i] ] end end end