Sha256: 67d149b383e5e9c29cacd303e91a86f590ffd8e2e3f0adf2a8dda6f60ea9fe5e

Contents?: true

Size: 528 Bytes

Versions: 1

Compression:

Stored size: 528 Bytes

Contents

# frozen_string_literal: true

module Sniffer
  # Data class stores the data and controls capacity
  class Data < Array
    def store(data_item)
      return unless config.store

      if config.rotate?
        rotate(data_item)
      else
        push(data_item) unless overflow?
      end
    end

    private

    def rotate(data_item)
      shift if overflow?
      push(data_item)
    end

    def overflow?
      config.capacity? && length >= config.capacity
    end

    def config
      Sniffer.config
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sniffer-0.2.0 lib/sniffer/data.rb