Module: UsefulUtilities::Size::Standard::Decimal
Overview
Used SI standard en.wikipedia.org/wiki/Binary_prefix
Constant Summary collapse
Instance Method Summary collapse
- #to_decimal_bi(val, prefix) ⇒ Object
- #to_giga(val, prefix) ⇒ Object
- #to_kilo(val, prefix) ⇒ Object
- #to_mega(val, prefix) ⇒ Object
- #to_tera(val, prefix) ⇒ Object
Instance Method Details
#to_decimal_bi(val, prefix) ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/useful_utilities/size/standard/decimal.rb', line 56 def to_decimal_bi(val, prefix) case prefix when :B then val when :KB then val * KILO when :MB then val * MEGA when :GB then val * GIGA when :TB then val * TERA else unsupported_unit!(prefix) end end |
#to_giga(val, prefix) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/useful_utilities/size/standard/decimal.rb', line 23 def to_giga(val, prefix) case prefix when :B then val.fdiv(GIGA) when :KB then val.fdiv(MEGA) when :MB then val.fdiv(KILO) when :GB then val when :TB then val * KILO else unsupported_unit!(prefix) end end |
#to_kilo(val, prefix) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/useful_utilities/size/standard/decimal.rb', line 45 def to_kilo(val, prefix) case prefix when :B then val.fdiv(KILO) when :KB then val when :MB then val * KILO when :GB then val * MEGA when :TB then val * GIGA else unsupported_unit!(prefix) end end |
#to_mega(val, prefix) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/useful_utilities/size/standard/decimal.rb', line 34 def to_mega(val, prefix) case prefix when :B then val.fdiv(MEGA) when :KB then val.fdiv(KILO) when :MB then val when :GB then val * KILO when :TB then val * MEGA else unsupported_unit!(prefix) end end |
#to_tera(val, prefix) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/useful_utilities/size/standard/decimal.rb', line 12 def to_tera(val, prefix) case prefix when :B then val.fdiv(TERA) when :KB then val.fdiv(GIGA) when :MB then val.fdiv(MEGA) when :GB then val.fdiv(KILO) when :TB then val else unsupported_unit!(prefix) end end |