Class: ExtendedLogger::Serializer::TextFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/extended_logger/serializer/text_formatter.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prose) ⇒ TextFormatter

Returns a new instance of TextFormatter.



6
7
8
# File 'lib/extended_logger/serializer/text_formatter.rb', line 6

def initialize prose
  @prose = prose
end

Instance Attribute Details

#proseObject (readonly)

Returns the value of attribute prose.



4
5
6
# File 'lib/extended_logger/serializer/text_formatter.rb', line 4

def prose
  @prose
end

Class Method Details

.call(prose) ⇒ Object



10
11
12
13
# File 'lib/extended_logger/serializer/text_formatter.rb', line 10

def self.call prose
  instance = new prose
  instance.()
end

Instance Method Details

#callObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/extended_logger/serializer/text_formatter.rb', line 15

def call
  return [ExtendedLogger.empty_message] if prose.nil? or prose.empty?

  lines.map do |line|
    line.chomp! if line.match %r{(?<!\r)\n}

    if line.empty?
      "\\n"
    else
      line = line.inspect
      line.slice! 0, 1
      line.slice! -1, 1
      line.gsub! '\\"', '"'
      line
    end
  end
end

#linesObject



33
34
35
# File 'lib/extended_logger/serializer/text_formatter.rb', line 33

def lines
  @lines ||= prose.each_line $INPUT_RECORD_SEPARATOR
end