Class: Trifle::Stats::Designator::Custom

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#bucketsObject (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