Class: StructuredDataToSql::Json::ExporterManifest

Inherits:
Object
  • Object
show all
Defined in:
lib/structured_data_to_sql/json/exporter_manifest.rb

Overview

Reads the Khoros exporter's manifest.json (kept beside the ndjson/ directory) just far enough to scope quality signals to the latest run. Everything is best-effort: a missing or unparsable manifest yields an instance with problem set and no runs; nothing here ever raises.

Defined Under Namespace

Classes: Run

Constant Summary collapse

FILENAME =
"manifest.json"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ ExporterManifest

Returns a new instance of ExporterManifest.



60
61
62
63
64
65
# File 'lib/structured_data_to_sql/json/exporter_manifest.rb', line 60

def initialize(path)
  @path = Pathname(path)
  @runs = []
  @problem = nil
  parse
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



33
34
35
# File 'lib/structured_data_to_sql/json/exporter_manifest.rb', line 33

def path
  @path
end

#problemObject (readonly)

Returns the value of attribute problem.



33
34
35
# File 'lib/structured_data_to_sql/json/exporter_manifest.rb', line 33

def problem
  @problem
end

#runsObject (readonly)

Returns the value of attribute runs.



33
34
35
# File 'lib/structured_data_to_sql/json/exporter_manifest.rb', line 33

def runs
  @runs
end

Class Method Details

.load(path) ⇒ Object



54
55
56
57
58
# File 'lib/structured_data_to_sql/json/exporter_manifest.rb', line 54

def self.load(path)
  return nil if path.nil?

  new(path)
end

.locate(source) ⇒ Object

Looks in the source directory itself and in its parent, so both export/ndjson and export/ work as the conversion source.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/structured_data_to_sql/json/exporter_manifest.rb', line 37

def self.locate(source)
  source = source.first if source.is_a?(Array)
  return nil unless source.is_a?(String) || source.is_a?(Pathname)

  base = Pathname(source)
  base = base.dirname if base.file?
  return nil unless base.directory?

  [base, base.parent].each do |directory|
    candidate = directory.join(FILENAME)
    return candidate if candidate.file?
  end
  nil
rescue SystemCallError
  nil
end

Instance Method Details

#errors_totalObject



71
72
73
# File 'lib/structured_data_to_sql/json/exporter_manifest.rb', line 71

def errors_total
  @runs.sum(&:errors)
end

#gaps_totalObject



75
76
77
# File 'lib/structured_data_to_sql/json/exporter_manifest.rb', line 75

def gaps_total
  @runs.sum(&:gaps)
end

#latest_completedObject



67
68
69
# File 'lib/structured_data_to_sql/json/exporter_manifest.rb', line 67

def latest_completed
  @runs.reverse.find(&:completed?)
end