Sha256: e4e367010a7afc1fe3d748680d8952dd73c9092172573b97d50179e6539a4247

Contents?: true

Size: 682 Bytes

Versions: 4

Compression:

Stored size: 682 Bytes

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'

module EhbrsRubyUtils
  class SpreaderT1
    module BaseLevel
      extend ::Comparable

      def <=>(other)
        s = remaining_f <=> other.remaining_f
        return s unless s.zero?

        s = total_i <=> other.total_i
        return s unless s.zero?

        label <=> other.label
      end

      def remaining?
        remaining_i.positive?
      end

      def remaining_f
        remaining_i.to_f / total_i
      end

      def remaining_fs
        ((remaining_f * 1000).round / 10.0).to_s + '%'
      end

      def debugs
        [label, remaining_fs, total_i].join(' / ')
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ehbrs_ruby_utils-0.17.3 lib/ehbrs_ruby_utils/spreader_t1/base_level.rb
ehbrs_ruby_utils-0.17.2 lib/ehbrs_ruby_utils/spreader_t1/base_level.rb
ehbrs_ruby_utils-0.17.1 lib/ehbrs_ruby_utils/spreader_t1/base_level.rb
ehbrs_ruby_utils-0.17.0 lib/ehbrs_ruby_utils/spreader_t1/base_level.rb