Class: FactoryTrace::TraceReader
- Inherits:
-
Object
- Object
- FactoryTrace::TraceReader
- Defined in:
- lib/factory_trace/readers/trace_reader.rb
Class Method Summary collapse
-
.read_from_files(*file_names, config: Configuration.new) ⇒ Array<Hash>
Read the data from files and merge it First hash - all factories Second hash - used factories.
Instance Method Summary collapse
-
#initialize(io, config: Configuration.new) ⇒ TraceReader
constructor
A new instance of TraceReader.
-
#read ⇒ Array<Hash>
Read the data from file First hash - all factories Second hash - used factories.
Constructor Details
#initialize(io, config: Configuration.new) ⇒ TraceReader
Returns a new instance of TraceReader.
20 21 22 23 |
# File 'lib/factory_trace/readers/trace_reader.rb', line 20 def initialize(io, config: Configuration.new) @io = io @config = config end |
Class Method Details
.read_from_files(*file_names, config: Configuration.new) ⇒ Array<Hash>
Read the data from files and merge it First hash - all factories Second hash - used factories
10 11 12 13 14 15 16 17 18 |
# File 'lib/factory_trace/readers/trace_reader.rb', line 10 def self.read_from_files(*file_names, config: Configuration.new) file_names.reduce([{}, {}]) do |array, file_name| reader = new(File.open(file_name, 'r'), config: config) new = reader.read array.each_with_index.map do |hash, index| hash.merge(new[index]) { |_key, v1, v2| v1 | v2 } end end end |
Instance Method Details
#read ⇒ Array<Hash>
Read the data from file First hash - all factories Second hash - used factories
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/factory_trace/readers/trace_reader.rb', line 30 def read data = [{}, {}] point = -1 io.each_line do |line| next point += 1 if line.match?(/-all-|-used-/) factory, *traits = line.strip.split(',') if factory data[point][factory] ||= Set.new data[point][factory] |= traits end end data end |