Sha256: 5747619a1aca2b705229db436844adfb550e9e858cb7b8302f650009a07ae8a1

Contents?: true

Size: 1.45 KB

Versions: 12

Compression:

Stored size: 1.45 KB

Contents

# frozen_string_literal: true

require_relative '../base'
require_relative '../events/event'

module Fusuma
  module Plugin
    module Detectors
      # Inherite this base
      class Detector < Base
        # @return [Array<String>]
        def sources
          @source ||= self.class.const_get('SOURCES')
        end

        # Always watch buffers and detect them or not
        # @return [TrueClass,FalseClass]
        def watch?
          false
        end

        # @param _buffers [Array<Buffer>]
        # @return [Event] if event is detected
        # @return [NilClass] if event is NOT detected
        def detect(_buffers)
          raise NotImplementedError, "override #{self.class.name}##{__method__}"

          # create_event(record:)
        end

        # @param record [Events::Records::Record]
        # @return [Events::Event]
        def create_event(record:)
          @last_time = Time.now
          Events::Event.new(time: @last_time, tag: tag, record: record)
        end

        def last_time
          @last_time ||= Time.now
        end

        def first_time?
          @last_time.nil?
        end

        def tag
          self.class.tag
        end

        def type
          self.class.type
        end

        class << self
          def tag
            name.split('Detectors::').last.underscore
          end

          def type(tag_name = tag)
            tag_name.gsub('_detector', '')
          end
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
fusuma-2.4.1 lib/fusuma/plugin/detectors/detector.rb
fusuma-2.4.0 lib/fusuma/plugin/detectors/detector.rb
fusuma-2.3.0 lib/fusuma/plugin/detectors/detector.rb
fusuma-2.2.0 lib/fusuma/plugin/detectors/detector.rb
fusuma-2.1.0 lib/fusuma/plugin/detectors/detector.rb
fusuma-2.0.5 lib/fusuma/plugin/detectors/detector.rb
fusuma-2.0.4 lib/fusuma/plugin/detectors/detector.rb
fusuma-2.0.3 lib/fusuma/plugin/detectors/detector.rb
fusuma-2.0.2 lib/fusuma/plugin/detectors/detector.rb
fusuma-2.0.1 lib/fusuma/plugin/detectors/detector.rb
fusuma-2.0.0 lib/fusuma/plugin/detectors/detector.rb
fusuma-2.0.0.pre2 lib/fusuma/plugin/detectors/detector.rb