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

Returns a new instance of Detector.



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

def initialize(*args)
  super(*args)
  @tag = self.class.tag
  @type = self.class.type
end

Instance Attribute Details

#tagObject (readonly)

Returns the value of attribute tag.



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

def tag
  @tag
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Class Method Details

.tagObject



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

def tag
  name.split("Detectors::").last.underscore
end

.type(tag_name = tag) ⇒ Object



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

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

Instance Method Details

#create_event(record:) ⇒ Events::Event

Parameters:

Returns:



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

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)


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

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

  # create_event(record:)
end

#first_time?Boolean

Returns:

  • (Boolean)


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

def first_time?
  @last_time.nil?
end

#last_timeObject



47
48
49
# File 'lib/fusuma/plugin/detectors/detector.rb', line 47

def last_time
  @last_time ||= Time.now
end

#sourcesArray<String>

Returns:



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

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

#watch?TrueClass, FalseClass

Always watch buffers and detect them or not

Returns:

  • (TrueClass, FalseClass)


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

def watch?
  false
end