Class: Woods::Export::UnitFacts

Inherits:
Object
  • Object
show all
Defined in:
lib/woods/export/unit_facts.rb

Overview

Format-agnostic extraction of facts from a unit's metadata.

Both the Unblocked and Obsidian exporters need the same facts about a unit — its associations grouped by macro, its schema highlights — but render them differently (plain text + GitHub URIs vs. wikilinks + frontmatter). This value object owns the one definition of "what a unit's metadata says"; each exporter is a thin formatter over it. The returned structures are deliberately raw (no truncation, no ordering imposed beyond the source array): formatting decisions — sort order, top-N caps — belong to each formatter so neither exporter's output is constrained by the other.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(unit) ⇒ UnitFacts

Returns a new instance of UnitFacts.

Parameters:

  • unit (Hash)

    parsed unit JSON



19
20
21
# File 'lib/woods/export/unit_facts.rb', line 19

def initialize(unit)
  @meta = (unit && unit['metadata']) || {}
end

Class Method Details

.blast_radius(dependent_count) ⇒ Symbol

Blast-radius bucket for a dependent count.

Parameters:

  • dependent_count (Integer)

Returns:

  • (Symbol)

    :high (>50), :moderate (>20), or :none



66
67
68
69
70
71
# File 'lib/woods/export/unit_facts.rb', line 66

def self.blast_radius(dependent_count)
  return :high if dependent_count > 50
  return :moderate if dependent_count > 20

  :none
end

Instance Method Details

#association_countInteger

Returns total association count across all macros.

Returns:

  • (Integer)

    total association count across all macros



35
36
37
# File 'lib/woods/export/unit_facts.rb', line 35

def association_count
  associations.size
end

#associations_by_typeHash{String=>Array<Hash>}

Associations grouped by macro, each as a structured entry. Group keys are whatever macros are present (insertion order from the source array); the formatter picks the display order.

Returns:

  • (Hash{String=>Array<Hash>})

    macro => [{ target:, dependent: }]



28
29
30
31
32
# File 'lib/woods/export/unit_facts.rb', line 28

def associations_by_type
  associations.group_by { |assoc| assoc['type'] }.transform_values do |items|
    items.map { |a| { target: a['target'] || a['name'], dependent: a.dig('options', 'dependent') } }
  end
end

#callbacksObject



56
57
58
59
60
# File 'lib/woods/export/unit_facts.rb', line 56

def callbacks
  return [] unless @meta['callbacks'].is_a?(Array)

  @meta['callbacks'].map { |cb| { type: cb['type'], filter: cb['filter'] } }
end

#concernsObject



52
53
54
# File 'lib/woods/export/unit_facts.rb', line 52

def concerns
  @meta['inlined_concerns'].is_a?(Array) ? @meta['inlined_concerns'] : []
end

#enumsObject



44
45
46
# File 'lib/woods/export/unit_facts.rb', line 44

def enums
  @meta['enums'].is_a?(Hash) ? @meta['enums'] : {}
end

#schema_highlightsHash

Returns { enums:, scopes:, concerns:, callbacks: } — raw, untruncated.

Returns:

  • (Hash)

    { enums:, scopes:, concerns:, callbacks: } — raw, untruncated



40
41
42
# File 'lib/woods/export/unit_facts.rb', line 40

def schema_highlights
  { enums: enums, scopes: scopes, concerns: concerns, callbacks: callbacks }
end

#scopesObject



48
49
50
# File 'lib/woods/export/unit_facts.rb', line 48

def scopes
  @meta['scopes'].is_a?(Array) ? @meta['scopes'].filter_map { |s| s['name'] } : []
end