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, #shutdown

Instance Method Details

#parse(event) ⇒ Event

Parse Event and convert Record and Tag if ‘#parse_record` return nil, this method will return original event : (Fusuma::Plugin::Events::Event) -> Fusuma::Plugin::Events::Event

Parameters:

  • event (Event)

Returns:

  • (Event)


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

def parse(event)
  return event if event.tag != source

  new_record = parse_record(event.record)
  return event if new_record.nil?

  event.record = new_record
  event.tag = tag
  event
end

#parse_record(_record) ⇒ Record?

parse Record object : (Fusuma::Plugin::Events::Records::Record) -> Fusuma::Plugin::Events::Records::Record?

Parameters:

  • _record (Record)

Returns:

  • (Record, nil)


43
44
45
# File 'lib/fusuma/plugin/parsers/parser.rb', line 43

def parse_record(_record)
  nil
end

#sourceObject

Set source for tag from config.yml. DEFAULT_SOURCE is defined in each Parser plugins. : () -> String



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

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

#tagObject

: () -> String



35
36
37
# File 'lib/fusuma/plugin/parsers/parser.rb', line 35

def tag
  @tag ||= self.class.name.split("::").last.underscore
end