Class: Trifle::Stats::Designator::Linear

Inherits:
Object
  • Object
show all
Defined in:
lib/trifle/stats/designator/linear.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(min:, max:, step:) ⇒ Linear

Returns a new instance of Linear.



9
10
11
12
13
# File 'lib/trifle/stats/designator/linear.rb', line 9

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

Instance Attribute Details

#maxObject (readonly)

Returns the value of attribute max.



7
8
9
# File 'lib/trifle/stats/designator/linear.rb', line 7

def max
  @max
end

#minObject (readonly)

Returns the value of attribute min.



7
8
9
# File 'lib/trifle/stats/designator/linear.rb', line 7

def min
  @min
end

#stepObject (readonly)

Returns the value of attribute step.



7
8
9
# File 'lib/trifle/stats/designator/linear.rb', line 7

def step
  @step
end

Instance Method Details

#designate(value:) ⇒ Object

rubocop:disable Metrics/AbcSize



15
16
17
18
19
20
# File 'lib/trifle/stats/designator/linear.rb', line 15

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