Sha256: 4472cc0ae576f2558aa0eb30c58abe12f7110861d39833923ba20e7f5bc46978

Contents?: true

Size: 632 Bytes

Versions: 3

Compression:

Stored size: 632 Bytes

Contents

# frozen_string_literal: true

module Lite
  module Measurements
    class DigitalStorage < Lite::Measurements::Base

      include Lite::Measurements::Helpers::ShiftHelper

      DIGITAL_STORAGE_UNITS ||= {
        bytes: 1.0, kilobytes: 1024.0, megabytes: 1024.0**2, gigabytes: 1024.0**3,
        terabytes: 1024.0**4, petabytes: 1024.05**5, exabytes: 1024**6
      }.freeze

      def convert(from:, to:)
        assert_all_valid_keys!(from, to, DIGITAL_STORAGE_UNITS.keys)
        return amount if equal_units?(from, to)

        shift_units(amount, type: DIGITAL_STORAGE_UNITS, from: from, to: to)
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
lite-measurements-1.0.2 lib/lite/measurements/digital_storage.rb
lite-measurements-1.0.1 lib/lite/measurements/digital_storage.rb
lite-measurements-1.0.0 lib/lite/measurements/digital_storage.rb