Class: LogMerge
- Inherits:
-
Object
- Object
- LogMerge
- Defined in:
- lib/logmerge.rb
Instance Attribute Summary collapse
-
#endTime ⇒ Object
readonly
Returns the value of attribute endTime.
-
#logs ⇒ Object
readonly
Returns the value of attribute logs.
-
#startTime ⇒ Object
readonly
Returns the value of attribute startTime.
Instance Method Summary collapse
-
#initialize(files, startTime = Time.at(0), endTime = Time.at(2000000000000)) ⇒ LogMerge
constructor
A new instance of LogMerge.
- #merge ⇒ Object
Constructor Details
#initialize(files, startTime = Time.at(0), endTime = Time.at(2000000000000)) ⇒ LogMerge
Returns a new instance of LogMerge.
72 73 74 75 76 |
# File 'lib/logmerge.rb', line 72 def initialize(files, startTime=Time.at(0), endTime=Time.at(2000000000000)) @logs = files.map {|f| Log.new(f)} @startTime = DateTime.parse(startTime.to_s) @endTime = DateTime.parse(endTime.to_s) end |
Instance Attribute Details
#endTime ⇒ Object (readonly)
Returns the value of attribute endTime.
71 72 73 |
# File 'lib/logmerge.rb', line 71 def endTime @endTime end |
#logs ⇒ Object (readonly)
Returns the value of attribute logs.
71 72 73 |
# File 'lib/logmerge.rb', line 71 def logs @logs end |
#startTime ⇒ Object (readonly)
Returns the value of attribute startTime.
71 72 73 |
# File 'lib/logmerge.rb', line 71 def startTime @startTime end |
Instance Method Details
#merge ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/logmerge.rb', line 78 def merge colors = Colored::COLORS.keys.dup colors.delete('black') while true min_log = logs.select {|l| !l.finished}.sort { |a,b| a. && b. ? a. <=> b. : b. ? -1 : 1 }.first #could be priority queue instead break if min_log.nil? next min_log.take unless min_log. next min_log.take if min_log. < startTime break if min_log.nil? break if min_log. > endTime index = logs.index(min_log) color_index = index % colors.size color = colors[color_index] puts Colored.colorize(min_log.take, foreground: color) end end |