Class: Archaeo::CoverageAnalyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/archaeo/coverage_report.rb

Overview

Builds a CoverageReport from CDX snapshot data.

Instance Method Summary collapse

Constructor Details

#initialize(cdx_api: nil) ⇒ CoverageAnalyzer

Returns a new instance of CoverageAnalyzer.



57
58
59
# File 'lib/archaeo/coverage_report.rb', line 57

def initialize(cdx_api: nil)
  @cdx_api = cdx_api
end

Instance Method Details

#analyze(url, from: nil, to: nil) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/archaeo/coverage_report.rb', line 61

def analyze(url, from: nil, to: nil)
  cdx = @cdx_api || CdxApi.new
  snapshots = cdx.snapshots(url, from: from, to: to).to_a

  unique_urls = snapshots.map(&:original_url).uniq
  status_dist = compute_status_distribution(snapshots)
  gaps = compute_temporal_gaps(snapshots)

  CoverageReport.new(
    url: url,
    total_urls: unique_urls.size,
    archived_urls: snapshots.count(&:success?),
    status_distribution: status_dist,
    temporal_gaps: gaps,
  )
end