Class: Cogger::Formatters::JSON

Inherits:
Abstract
  • Object
show all
Defined in:
lib/cogger/formatters/json.rb

Overview

Formats as JSON output.

Constant Summary collapse

TEMPLATE =
nil

Constants inherited from Abstract

Abstract::NEW_LINE, Abstract::SANITIZERS

Instance Method Summary collapse

Constructor Details

#initialize(template = TEMPLATE, parser: Parsers::Position.new) ⇒ JSON

Returns a new instance of JSON.



12
13
14
15
16
# File 'lib/cogger/formatters/json.rb', line 12

def initialize template = TEMPLATE, parser: Parsers::Position.new
  super()
  @template = template
  @parser = parser
end

Instance Method Details

#call(*input) ⇒ Object



18
19
20
21
22
23
# File 'lib/cogger/formatters/json.rb', line 18

def call(*input)
  *, entry = input
  attributes = sanitize(entry, :tagged_attributes).tap(&:compact!)

  parser.call(template, attributes).to_json << NEW_LINE
end