Sha256: 6d701d4f8068cf70bf51bfe1767db2d91a6c5d64aea1a2a28a441fd68bf1436e
Contents?: true
Size: 643 Bytes
Versions: 2
Compression:
Stored size: 643 Bytes
Contents
class Time def to_alpha strftime '%H.%M' end end class Fixnum def to_alpha return to_s if self < 1000 return self.to_f.to_alpha end end class Float def to_alpha(len = 4) v = self.to_f prefixes = ['', 'k', 'M', 'G', 'T'] pref_index = 0 if v.round.to_s.length > len while v.abs > 1000 v = v / 1000 pref_index += 1 end if v < 0 && v.abs >= 100 v = v / 1000 pref_index += 1 end end pref = prefixes[pref_index] digits = len - pref.length decimals = digits - v.abs.to_i.to_s.length - (v < 0 ? 1 : 0) return ("%.#{decimals}f" % v) + pref end def to_ts TimeSpan.new self end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
i2c-alpha_display-0.5.1 | lib/i2c/alpha_display/extensions.rb |
i2c-alpha_display-0.3.0 | lib/i2c/alpha_display/extensions.rb |