Class: DatasetExplorer::Collector

Inherits:
Object
  • Object
show all
Defined in:
lib/dataset_explorer/collector.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCollector

Returns a new instance of Collector.



9
10
11
# File 'lib/dataset_explorer/collector.rb', line 9

def initialize
  @collectors = {}
end

Class Method Details

.instanceObject



5
6
7
# File 'lib/dataset_explorer/collector.rb', line 5

def self.instance
  @instance ||= new
end

Instance Method Details

#collect(type, item) ⇒ Object



13
14
15
# File 'lib/dataset_explorer/collector.rb', line 13

def collect(type, item)
  collector_for(type).add(item)
end

#explain(type, format: :hash) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/dataset_explorer/collector.rb', line 23

def explain(type, format: :hash)
  explanation = @collectors.fetch(type).explain

  if format == :table
    explanation = to_table(explanation)
  end

  explanation
end

#explain_all(format: :hash) ⇒ Object



17
18
19
20
21
# File 'lib/dataset_explorer/collector.rb', line 17

def explain_all(format: :hash)
  @collectors.keys.map do |key|
    [key, explain(key, format: format)]
  end.to_h
end