Class: Markbridge::Normalizer::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/markbridge/normalizer/report.rb

Overview

Tally of the transformations a single #normalize pass applied. Held as a local per call (never on the Normalizer), so a frozen shared instance stays reusable and thread-safe.

Instance Method Summary collapse

Constructor Details

#initializeReport

Returns a new instance of Report.



9
10
11
# File 'lib/markbridge/normalizer/report.rb', line 9

def initialize
  @counts = Hash.new(0)
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/markbridge/normalizer/report.rb', line 21

def empty?
  @counts.empty?
end

#record(parent_class, child_class, strategy) ⇒ Object

Parameters:

  • parent_class (Class)

    the offending ancestor's class

  • child_class (Class)

    the moved/removed node's class

  • strategy (Symbol)

    the strategy actually applied



16
17
18
# File 'lib/markbridge/normalizer/report.rb', line 16

def record(parent_class, child_class, strategy)
  @counts[[demodulize(parent_class), demodulize(child_class), strategy]] += 1
end

#to_aArray<Hash>

One {parent:, child:, strategy:, count:} row per distinct transformation, e.g. {parent: "Url", child: "Image", strategy: :hoist_after, count: 3}.

Returns:

  • (Array<Hash>)


30
31
32
# File 'lib/markbridge/normalizer/report.rb', line 30

def to_a
  @counts.map { |(parent, child, strategy), count| { parent:, child:, strategy:, count: } }
end