Module: Familia::Features::Quantizer
- Defined in:
- lib/familia/features/quantizer.rb
Instance Method Summary collapse
-
#qstamp(quantum = nil, pattern = nil, now = Familia.now) ⇒ Object
From Familia::RedisType.
Instance Method Details
#qstamp(quantum = nil, pattern = nil, now = Familia.now) ⇒ Object
From Familia::RedisType
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/familia/features/quantizer.rb', line 9 def qstamp(quantum = nil, pattern = nil, now = Familia.now) quantum ||= @opts[:quantize] || ttl || 10.minutes case quantum when Numeric # Handle numeric quantum (e.g., seconds, minutes) when Array quantum, pattern = *quantum end now ||= Familia.now rounded = now - (now % quantum) if pattern.nil? Time.at(rounded).utc.to_i # 3605 -> 3600 else Time.at(rounded).utc.strftime(pattern || '%H%M') # 3605 -> '1:00' end end |