Class: Ucode::Audit::Release::FaceCard

Inherits:
Object
  • Object
show all
Defined in:
lib/ucode/audit/release/face_card.rb

Overview

Value object deriving the per-face card fields shared by LibraryIndexBuilder (Hash for library.json) and ManifestBuilder (Models::Audit::ReleaseFaceEntry for manifest.json).

Single source of truth for the rollup math (covered total, assigned total, complete/partial block counts) and the path conventions (face label sanitization, relative index/html paths under <release_root>/audit/<slug>/<label>/).

Pure: no I/O, no mutation. Callers compose the final shape (Hash or model) from the derived fields.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(report, slug, release_root) ⇒ FaceCard

Returns a new instance of FaceCard.

Parameters:



29
30
31
32
33
# File 'lib/ucode/audit/release/face_card.rb', line 29

def initialize(report, slug, release_root)
  @report = report
  @slug = slug
  @release_root = release_root
end

Instance Attribute Details

#release_rootObject (readonly)

Returns the value of attribute release_root.



24
25
26
# File 'lib/ucode/audit/release/face_card.rb', line 24

def release_root
  @release_root
end

#reportObject (readonly)

Returns the value of attribute report.



24
25
26
# File 'lib/ucode/audit/release/face_card.rb', line 24

def report
  @report
end

#slugObject (readonly)

Returns the value of attribute slug.



24
25
26
# File 'lib/ucode/audit/release/face_card.rb', line 24

def slug
  @slug
end

Instance Method Details

#assigned_totalInteger

Returns:

  • (Integer)


53
54
55
# File 'lib/ucode/audit/release/face_card.rb', line 53

def assigned_total
  report.blocks.sum(&:total_assigned)
end

#blocks_completeInteger

Returns:

  • (Integer)


58
59
60
61
62
# File 'lib/ucode/audit/release/face_card.rb', line 58

def blocks_complete
  report.blocks.count do |b|
    b.status == Models::Audit::BlockSummary::STATUS_COMPLETE
  end
end

#blocks_partialInteger

Returns:

  • (Integer)


65
66
67
68
69
# File 'lib/ucode/audit/release/face_card.rb', line 65

def blocks_partial
  report.blocks.count do |b|
    b.status == Models::Audit::BlockSummary::STATUS_PARTIAL
  end
end

#covered_totalInteger

Returns:

  • (Integer)


48
49
50
# File 'lib/ucode/audit/release/face_card.rb', line 48

def covered_total
  report.blocks.sum(&:covered_count)
end

#face_dirPathname

Returns <release_root>/audit/<slug>/<label>.

Returns:

  • (Pathname)

    <release_root>/audit/<slug>/<label>



43
44
45
# File 'lib/ucode/audit/release/face_card.rb', line 43

def face_dir
  Ucode::Audit::Emitter::Paths.release_face_dir(release_root, slug, label)
end

#html_pathString

Returns relative path from release root to index.html.

Returns:

  • (String)

    relative path from release root to index.html



77
78
79
# File 'lib/ucode/audit/release/face_card.rb', line 77

def html_path
  relative_path(face_dir.join("index.html"))
end

#index_pathString

Returns relative path from release root to index.json.

Returns:

  • (String)

    relative path from release root to index.json



72
73
74
# File 'lib/ucode/audit/release/face_card.rb', line 72

def index_path
  relative_path(face_dir.join("index.json"))
end

#labelString

Returns sanitized face label (postscript name with non-filename chars replaced by underscore).

Returns:

  • (String)

    sanitized face label (postscript name with non-filename chars replaced by underscore)



37
38
39
40
# File 'lib/ucode/audit/release/face_card.rb', line 37

def label
  name = report.postscript_name || File.basename(report.source_file.to_s, ".*")
  (name || "face").to_s.gsub(/[^A-Za-z0-9._-]/, "_")
end