class DatasetExplorer::Collector
Public Class Methods
instance()
click to toggle source
# File lib/dataset_explorer/collector.rb, line 5 def self.instance @instance ||= new end
Private Class Methods
new()
click to toggle source
# File lib/dataset_explorer/collector.rb, line 9 def initialize @collectors = {} end
Public Instance Methods
collect(type, item)
click to toggle source
# File lib/dataset_explorer/collector.rb, line 13 def collect(type, item) collector_for(type).add(item) end
explain(type, format: :hash)
click to toggle source
# 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)
click to toggle source
# 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
Private Instance Methods
collector_for(type)
click to toggle source
# File lib/dataset_explorer/collector.rb, line 35 def collector_for(type) @collectors[type] ||= ItemCollector.new end
to_table(fields)
click to toggle source
# File lib/dataset_explorer/collector.rb, line 39 def to_table(fields) rows = [] fields.each do |key, description| rows << [key, description] end Terminal::Table.new(rows: rows) end