Class: ORS::LogUnifier

Inherits:
Object
  • Object
show all
Defined in:
lib/ors/log_unifier.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logs) ⇒ LogUnifier

Returns a new instance of LogUnifier.



7
8
9
10
11
12
13
14
15
# File 'lib/ors/log_unifier.rb', line 7

def initialize logs
  @pretty_adjust = 0

  @logs = logs.inject(Hash.new) do |hash, (server, log_rows)|
    @pretty_adjust = [@pretty_adjust, server.length].max
    hash[server] = log_rows
    hash
  end
end

Instance Attribute Details

#logsObject (readonly)

Returns the value of attribute logs.



5
6
7
# File 'lib/ors/log_unifier.rb', line 5

def logs
  @logs
end

#pretty_adjustObject (readonly)

Returns the value of attribute pretty_adjust.



5
6
7
# File 'lib/ors/log_unifier.rb', line 5

def pretty_adjust
  @pretty_adjust
end

Instance Method Details

#unifyObject



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ors/log_unifier.rb', line 17

def unify
  group_by_entry.
    select {|entry| entry[:timestamp].size == 14 }.
    sort_by {|entry| entry[:timestamp] }.
    map do |entry|
      entry[:lines].
      map {|line| ["[#{entry[:server]}]".ljust(pretty_adjust + 3), line].join.strip }.
      join "\n"
    end.
    flatten.
    join("\n\n\n")
end