Class: Fluent::EverySenseInput::EverySenseParser

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent/plugin/in_everysense.rb

Overview

currently EverySenseParser is only used by EverySense Plugin Parser is implemented internally.

Instance Method Summary collapse

Constructor Details

#initialize(format, parser) ⇒ EverySenseParser

Returns a new instance of EverySenseParser.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/fluent/plugin/in_everysense.rb', line 11

def initialize(format, parser)
  case format
  when 'json'
    @parser = parser
    return
  when 'xml'
    raise NotImplementedError, "XML parser is not implemented yet."
  else
    raise NotImplementedError, "XML parser is not implemented yet."
  end
end

Instance Method Details

#parse(messages) ⇒ Object

TODO: parser should be impelented prettier way… currently once parse JSON array is parsed and in map loop each message is re-formatted to JSON. After that it is re-parsed by fluent JSON parser which supports time_format etc. options…



27
28
29
30
31
32
33
34
35
# File 'lib/fluent/plugin/in_everysense.rb', line 27

def parse(messages)
  $log.debug messages
  JSON.parse(messages).map do |message|
    $log.debug message
    @parser.parse(message.to_json) do |time, record|
      yield(time, record)
    end
  end
end