Module: UsefulUtilities::Size::Standard::Binary
- Included in:
- Byte
- Defined in:
- lib/useful_utilities/size/standard/binary.rb
Overview
Possible prefixes:
:B - bytes
:KiB - kibibytes
:MiB - mebibytes
:GiB - gibibytes
:TiB - tebibytes
Used ISO standard en.wikipedia.org/wiki/Binary_prefix
Constant Summary collapse
Instance Method Summary collapse
-
#to_binary_bi(val, prefix) ⇒ Numeric
Val in bytes.
-
#to_gibi(val, prefix) ⇒ Numeric
Val in gibibytes.
-
#to_kibi(val, prefix) ⇒ Numeric
Val in kibibytes.
-
#to_mebi(val, prefix) ⇒ Numeric
Val in mebibytes.
-
#to_tebi(val, prefix) ⇒ Numeric
Val in tebibytes.
Instance Method Details
#to_binary_bi(val, prefix) ⇒ Numeric
Returns val in bytes.
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/useful_utilities/size/standard/binary.rb', line 77 def to_binary_bi(val, prefix) case prefix when :B then val when :KiB then val * KIBI when :MiB then val * MEBI when :GiB then val * GIBI when :TiB then val * TEBI else unsupported_unit!(prefix) end end |
#to_gibi(val, prefix) ⇒ Numeric
Returns val in gibibytes.
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/useful_utilities/size/standard/binary.rb', line 35 def to_gibi(val, prefix) case prefix when :B then val.fdiv(GIBI) when :KiB then val.fdiv(MEBI) when :MiB then val.fdiv(KIBI) when :GiB then val when :TiB then val * KIBI else unsupported_unit!(prefix) end end |
#to_kibi(val, prefix) ⇒ Numeric
Returns val in kibibytes.
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/useful_utilities/size/standard/binary.rb', line 63 def to_kibi(val, prefix) case prefix when :B then val.fdiv(KIBI) when :KiB then val when :MiB then val * KIBI when :GiB then val * MEBI when :TiB then val * GIBI else unsupported_unit!(prefix) end end |
#to_mebi(val, prefix) ⇒ Numeric
Returns val in mebibytes.
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/useful_utilities/size/standard/binary.rb', line 49 def to_mebi(val, prefix) case prefix when :B then val.fdiv(MEBI) when :KiB then val.fdiv(KIBI) when :MiB then val when :GiB then val * KIBI when :TiB then val * MEBI else unsupported_unit!(prefix) end end |
#to_tebi(val, prefix) ⇒ Numeric
Returns val in tebibytes.
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/useful_utilities/size/standard/binary.rb', line 21 def to_tebi(val, prefix) case prefix when :B then val.fdiv(TEBI) when :KiB then val.fdiv(GIBI) when :MiB then val.fdiv(MEBI) when :GiB then val.fdiv(KIBI) when :TiB then val else unsupported_unit!(prefix) end end |