Class: Trifle::Stats::Designator::Geometric
- Inherits:
-
Object
- Object
- Trifle::Stats::Designator::Geometric
- Defined in:
- lib/trifle/stats/designator/geometric.rb
Instance Attribute Summary collapse
-
#max ⇒ Object
readonly
Returns the value of attribute max.
-
#min ⇒ Object
readonly
Returns the value of attribute min.
Instance Method Summary collapse
-
#designate(value:) ⇒ Object
rubocop:disable Metrics/AbcSize.
-
#initialize(min:, max:) ⇒ Geometric
constructor
A new instance of Geometric.
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
#max ⇒ Object (readonly)
Returns the value of attribute max.
7 8 9 |
# File 'lib/trifle/stats/designator/geometric.rb', line 7 def max @max end |
#min ⇒ Object (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 |