Class: Trifle::Stats::Designator::Custom
- Inherits:
-
Object
- Object
- Trifle::Stats::Designator::Custom
- Defined in:
- lib/trifle/stats/designator/custom.rb
Instance Attribute Summary collapse
-
#buckets ⇒ Object
readonly
Returns the value of attribute buckets.
Instance Method Summary collapse
- #designate(value:) ⇒ Object
-
#initialize(buckets:) ⇒ Custom
constructor
A new instance of Custom.
Constructor Details
#initialize(buckets:) ⇒ Custom
Returns a new instance of Custom.
9 10 11 |
# File 'lib/trifle/stats/designator/custom.rb', line 9 def initialize(buckets:) @buckets = buckets.sort end |
Instance Attribute Details
#buckets ⇒ Object (readonly)
Returns the value of attribute buckets.
7 8 9 |
# File 'lib/trifle/stats/designator/custom.rb', line 7 def buckets @buckets end |
Instance Method Details
#designate(value:) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/trifle/stats/designator/custom.rb', line 13 def designate(value:) return buckets.first.to_s if value <= buckets.first return "#{buckets.last}+" if value > buckets.last (buckets.find { |b| value.ceil < b }).to_s end |