Class: Woods::Export::UnitFacts
- Inherits:
-
Object
- Object
- Woods::Export::UnitFacts
- 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
-
.blast_radius(dependent_count) ⇒ Symbol
Blast-radius bucket for a dependent count.
Instance Method Summary collapse
-
#association_count ⇒ Integer
Total association count across all macros.
-
#associations_by_type ⇒ Hash{String=>Array<Hash>}
Associations grouped by macro, each as a structured entry.
- #callbacks ⇒ Object
- #concerns ⇒ Object
- #enums ⇒ Object
-
#initialize(unit) ⇒ UnitFacts
constructor
A new instance of UnitFacts.
-
#schema_highlights ⇒ Hash
{ enums:, scopes:, concerns:, callbacks: } — raw, untruncated.
- #scopes ⇒ Object
Constructor Details
#initialize(unit) ⇒ UnitFacts
Returns a new instance of UnitFacts.
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.
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_count ⇒ Integer
Returns 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_type ⇒ Hash{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.
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 |
#callbacks ⇒ Object
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 |
#concerns ⇒ Object
52 53 54 |
# File 'lib/woods/export/unit_facts.rb', line 52 def concerns @meta['inlined_concerns'].is_a?(Array) ? @meta['inlined_concerns'] : [] end |
#enums ⇒ Object
44 45 46 |
# File 'lib/woods/export/unit_facts.rb', line 44 def enums @meta['enums'].is_a?(Hash) ? @meta['enums'] : {} end |
#schema_highlights ⇒ Hash
Returns { 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 |
#scopes ⇒ Object
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 |