Sha256: ac1d46252a93a269eb6b819295ce5fa9303b9b4a0b230ea85c8632fd594bbcca

Contents?: true

Size: 536 Bytes

Versions: 5

Compression:

Stored size: 536 Bytes

Contents

# frozen_string_literal: true

module Trifle
  module Stats
    class Designator
      class Linear
        attr_reader :min, :max, :step

        def initialize(min:, max:, step:)
          @min = min
          @max = max
          @step = step.to_i
        end

        def designate(value:) # rubocop:disable Metrics/AbcSize
          return min.to_s if value <= min
          return "#{max}+" if value > max

          (value.ceil / step * step + ((value.ceil % step).zero? ? 0 : step)).to_s
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
trifle-stats-1.3.1 lib/trifle/stats/designator/linear.rb
trifle-stats-1.3.0 lib/trifle/stats/designator/linear.rb
trifle-stats-1.2.0 lib/trifle/stats/designator/linear.rb
trifle-stats-1.1.2 lib/trifle/stats/designator/linear.rb
trifle-stats-1.1.1 lib/trifle/stats/designator/linear.rb