Class: Trifle::Stats::Designator::Geometric

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(min:, max:) ⇒ Geometric

Returns a new instance of Geometric.



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

def initialize(min:, max:)
  @min = min.negative? ? 0 : min
  @max = max
end

Instance Attribute Details

#maxObject (readonly)

Returns the value of attribute max.



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

def max
  @max
end

#minObject (readonly)

Returns the value of attribute min.



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

def min
  @min
end

Instance Method Details

#designate(value:) ⇒ Object

rubocop:disable Metrics/AbcSize



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

def designate(value:) # rubocop:disable Metrics/AbcSize
  return min.to_f.to_s if value <= min
  return "#{max.to_f}+" if value > max
  return (10**value.floor.to_s.length).to_f.to_s if value > 1
  return 1.0.to_s if value > 0.1 # ugh?

  (1.0 / 10**value.to_s.gsub('0.', '').split(/[1-9]/).first.length).to_s
end