Class: StructuredDataToSql::ConversionResult

Inherits:
Object
  • Object
show all
Includes:
ImmutableValue
Defined in:
lib/structured_data_to_sql/conversion_result.rb

Constant Summary collapse

COMMON_KEYS =
%i[
  format
  files_processed
  files_skipped
  tables_processed
  tables_skipped
  rows_processed
  child_rows_processed
  bytes_read
  bytes_written
  warnings
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(format:, metrics: {}) ⇒ ConversionResult

Returns a new instance of ConversionResult.



37
38
39
40
41
42
# File 'lib/structured_data_to_sql/conversion_result.rb', line 37

def initialize(format:, metrics: {})
  values = metrics.transform_keys(&:to_sym).merge(format: format.to_sym)
  COMMON_KEYS.each { |key| values[key] ||= key == :warnings ? [] : 0 }
  @values = deep_freeze(values.dup)
  freeze
end

Instance Method Details

#[](key) ⇒ Object



44
45
46
# File 'lib/structured_data_to_sql/conversion_result.rb', line 44

def [](key)
  @values[key.to_sym]
end

#fetchObject



48
49
50
# File 'lib/structured_data_to_sql/conversion_result.rb', line 48

def fetch(...)
  @values.fetch(...)
end

#metricsObject



56
57
58
# File 'lib/structured_data_to_sql/conversion_result.rb', line 56

def metrics
  @values.reject { |key, _| COMMON_KEYS.include?(key) }.freeze
end

#to_hObject



52
53
54
# File 'lib/structured_data_to_sql/conversion_result.rb', line 52

def to_h
  @values.dup
end