Class: Fusuma::Plugin::Detectors::Detector

Inherits:
Base
  • Object
show all
Defined in:
lib/fusuma/plugin/detectors/detector.rb

Overview

Inherite this base

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#config_index, #config_param_types, #config_params, inherited, plugins, #shutdown

Constructor Details

#initialize(*args) ⇒ Detector

: (*nil) -> void



16
17
18
19
20
# File 'lib/fusuma/plugin/detectors/detector.rb', line 16

def initialize(*args)
  super
  @tag = self.class.name.split("Detectors::").last.underscore
  @type = self.class.type(@tag)
end

Instance Attribute Details

#tagObject (readonly)

: String



22
23
24
# File 'lib/fusuma/plugin/detectors/detector.rb', line 22

def tag
  @tag
end

#typeObject (readonly)

: String



23
24
25
# File 'lib/fusuma/plugin/detectors/detector.rb', line 23

def type
  @type
end

Class Method Details

.type(tag_name) ⇒ Object



11
12
13
# File 'lib/fusuma/plugin/detectors/detector.rb', line 11

def self.type(tag_name)
  tag_name.gsub("_detector", "")
end

Instance Method Details

#create_event(record:) ⇒ Events::Event

: (record: Fusuma::Plugin::Events::Records::IndexRecord) -> Fusuma::Plugin::Events::Event

Parameters:

Returns:



50
51
52
53
# File 'lib/fusuma/plugin/detectors/detector.rb', line 50

def create_event(record:)
  @last_time = Time.now
  Events::Event.new(time: @last_time, tag: @tag, record: record)
end

#detect(_buffers) ⇒ Event, NilClass

Parameters:

  • _buffers (Array<Buffer>)

Returns:

  • (Event)

    if event is detected

  • (NilClass)

    if event is NOT detected

Raises:

  • (NotImplementedError)


41
42
43
44
45
# File 'lib/fusuma/plugin/detectors/detector.rb', line 41

def detect(_buffers)
  raise NotImplementedError, "override #{self.class.name}##{__method__}"

  # create_event(record:)
end

#first_time?Boolean

: () -> bool

Returns:

  • (Boolean)


61
62
63
# File 'lib/fusuma/plugin/detectors/detector.rb', line 61

def first_time?
  @last_time.nil?
end

#last_timeObject

: () -> Time



56
57
58
# File 'lib/fusuma/plugin/detectors/detector.rb', line 56

def last_time
  @last_time ||= Time.now
end

#sourcesArray<String>

: () -> Array

Returns:



27
28
29
# File 'lib/fusuma/plugin/detectors/detector.rb', line 27

def sources
  @sources ||= self.class.const_get(:SOURCES)
end

#watch?TrueClass, FalseClass

Always watch buffers and detect them or not : () -> bool

Returns:

  • (TrueClass, FalseClass)


34
35
36
# File 'lib/fusuma/plugin/detectors/detector.rb', line 34

def watch?
  false
end