Class: Fusuma::Plugin::Parsers::Parser

Inherits:
Base
  • Object
show all
Defined in:
lib/fusuma/plugin/parsers/parser.rb

Overview

Parser change record and tag in event Inherite this base class

Direct Known Subclasses

LibinputGestureParser

Instance Method Summary collapse

Methods inherited from Base

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

Instance Method Details

#parse(event) ⇒ Event

Parse Event and convert Record and Tag if ‘#parse_record` return nil, this method will return original event

Parameters:

  • event (Event)

Returns:

  • (Event)


15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fusuma/plugin/parsers/parser.rb', line 15

def parse(event)
  event.tap do |e|
    next if e.tag != source

    new_record = parse_record(e.record)
    next unless new_record

    e.record = new_record
    e.tag = tag
  end
end

#parse_record(_record) ⇒ Record?

parse Record object

Parameters:

  • _record (Record)

Returns:

  • (Record, nil)


40
41
42
# File 'lib/fusuma/plugin/parsers/parser.rb', line 40

def parse_record(_record)
  nil
end

#sourceObject

Set source for tag from config.yml. DEFAULT_SOURCE is defined in each Parser plugins.



29
30
31
# File 'lib/fusuma/plugin/parsers/parser.rb', line 29

def source
  @source ||= config_params(:source) || self.class.const_get('DEFAULT_SOURCE')
end

#tagObject



33
34
35
# File 'lib/fusuma/plugin/parsers/parser.rb', line 33

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