Sha256: 17ff0589cee481736d817d22c1ccaa305876f82a116a94f75f6b4bae2f11e6c6

Contents?: true

Size: 543 Bytes

Versions: 3

Compression:

Stored size: 543 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 data_item.allowed_to_sniff?

      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

3 entries across 3 versions & 1 rubygems

Version Path
sniffer-0.3.2 lib/sniffer/data.rb
sniffer-0.3.1 lib/sniffer/data.rb
sniffer-0.3.0 lib/sniffer/data.rb