sonic-pi
https://github.com/sonic-pi-net/sonic-pi
C++
Code. Music. Live.
ActiveSupport::NumberHelper#number_to_human_size
Formats the bytes in +number+ into a more understandable representation (e.g., giving it 1500 yields 1.5 KB). This method is useful for reporting file sizes to users. You can customize the format in the +options+ hash. See <tt>number_to_human</tt> if you want to pretty-print a generic number. ==== Options * <tt>:locale</tt> - Sets the locale to be used for formatting (defaults to current locale). * <tt>:precision</tt> - Sets the precision of the number (defaults to 3). * <tt>:significant</tt> - If +true+, precision will be the # of significant_digits. If +false+, the # of fractional digits (defaults to +true+) * <tt>:separator</tt> - Sets the separator between the fractional and integer digits (defaults to "."). * <tt>:delimiter</tt> - Sets the thousands delimiter (defaults to ""). * <tt>:strip_insignificant_zeros</tt> - If +true+ removes insignificant zeros after the decimal separator (defaults to +true+) * <tt>:prefix</tt> - If +:si+ formats the number using the SI prefix (defaults to :binary) ==== Examples number_to_human_size(123) # => 123 Bytes number_to_human_size(1234) # => 1.21 KB number_to_human_size(12345) # => 12.1 KB number_to_human_size(1234567) # => 1.18 MB number_to_human_size(1234567890) # => 1.15 GB number_to_human_size(1234567890123) # => 1.12 TB number_to_human_size(1234567, precision: 2) # => 1.2 MB number_to_human_size(483989, precision: 2) # => 470 KB number_to_human_size(1234567, precision: 2, separator: ',') # => 1,2 MB Non-significant zeros after the fractional separator are stripped out by default (set <tt>:strip_insignificant_zeros</tt> to +false+ to change that): number_to_human_size(1234567890123, precision: 5) # => "1.1229 TB" number_to_human_size(524288000, precision: 5) # => "500 MB"
Edit
git clone [email protected]:sonic-pi-net/sonic-pi.git
cd sonic-pi
open app/server/ruby/vendor/activesupport-7.0.6/lib/active_support/number_helper.rb
Contribute
# Make a new branchgit checkout -b -your-name--update-docs-ActiveSupport--NumberHelper-number_to_human_size-for-pr
# Commit to gitgit add app/server/ruby/vendor/activesupport-7.0.6/lib/active_support/number_helper.rbgit commit -m "better docs for ActiveSupport::NumberHelper#number_to_human_size"
# Open pull requestgem install hub # on a mac you can `brew install hub`
hub fork
git push <your name> -your-name--update-docs-ActiveSupport--NumberHelper-number_to_human_size-for-pr
hub pull-request
# Celebrate!