Class: Ast::Merge::Layout::Augmenter
- Inherits:
-
Object
- Object
- Ast::Merge::Layout::Augmenter
- Includes:
- Ast::Merge::LineRangeSupport
- Defined in:
- lib/ast/merge/layout/augmenter.rb
Overview
Builds shared blank-line gap objects and per-owner attachments from source lines plus structural owner ranges.
Instance Attribute Summary collapse
-
#attachments_by_owner ⇒ Object
readonly
Returns the value of attribute attachments_by_owner.
-
#interstitial_gaps ⇒ Object
readonly
Returns the value of attribute interstitial_gaps.
-
#lines ⇒ Object
readonly
Returns the value of attribute lines.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#owners ⇒ Object
readonly
Returns the value of attribute owners.
-
#postlude_gap ⇒ Object
readonly
Returns the value of attribute postlude_gap.
-
#preamble_gap ⇒ Object
readonly
Returns the value of attribute preamble_gap.
Class Method Summary collapse
-
.call(**options) ⇒ Augmenter
Build an augmenter and run gap inference immediately.
Instance Method Summary collapse
-
#attachment_for(owner) ⇒ Attachment?
Return the inferred attachment for a specific owner.
-
#gaps ⇒ Array<Gap>
Return all inferred gaps in source order.
-
#initialize(lines: nil, source: nil, owners: [], start_line_for: nil, end_line_for: nil, metadata: {}, **options) ⇒ Augmenter
constructor
A new instance of Augmenter.
Constructor Details
#initialize(lines: nil, source: nil, owners: [], start_line_for: nil, end_line_for: nil, metadata: {}, **options) ⇒ Augmenter
Returns a new instance of Augmenter.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ast/merge/layout/augmenter.rb', line 23 def initialize(lines: nil, source: nil, owners: [], start_line_for: nil, end_line_for: nil, metadata: {}, **) @lines = normalize_lines(lines, source) @start_line_for = start_line_for @end_line_for = end_line_for @owners = normalize_owners(owners) @metadata = .merge().freeze @attachments_by_owner = {} @preamble_gap = nil @postlude_gap = nil @interstitial_gaps = [] build! end |
Instance Attribute Details
#attachments_by_owner ⇒ Object (readonly)
Returns the value of attribute attachments_by_owner.
11 12 13 |
# File 'lib/ast/merge/layout/augmenter.rb', line 11 def @attachments_by_owner end |
#interstitial_gaps ⇒ Object (readonly)
Returns the value of attribute interstitial_gaps.
11 12 13 |
# File 'lib/ast/merge/layout/augmenter.rb', line 11 def interstitial_gaps @interstitial_gaps end |
#lines ⇒ Object (readonly)
Returns the value of attribute lines.
11 12 13 |
# File 'lib/ast/merge/layout/augmenter.rb', line 11 def lines @lines end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
11 12 13 |
# File 'lib/ast/merge/layout/augmenter.rb', line 11 def @metadata end |
#owners ⇒ Object (readonly)
Returns the value of attribute owners.
11 12 13 |
# File 'lib/ast/merge/layout/augmenter.rb', line 11 def owners @owners end |
#postlude_gap ⇒ Object (readonly)
Returns the value of attribute postlude_gap.
11 12 13 |
# File 'lib/ast/merge/layout/augmenter.rb', line 11 def postlude_gap @postlude_gap end |
#preamble_gap ⇒ Object (readonly)
Returns the value of attribute preamble_gap.
11 12 13 |
# File 'lib/ast/merge/layout/augmenter.rb', line 11 def preamble_gap @preamble_gap end |
Class Method Details
.call(**options) ⇒ Augmenter
Build an augmenter and run gap inference immediately.
18 19 20 |
# File 'lib/ast/merge/layout/augmenter.rb', line 18 def call(**) new(**) end |
Instance Method Details
#attachment_for(owner) ⇒ Attachment?
Return the inferred attachment for a specific owner.
42 43 44 |
# File 'lib/ast/merge/layout/augmenter.rb', line 42 def (owner) [owner] end |
#gaps ⇒ Array<Gap>
Return all inferred gaps in source order.
49 50 51 |
# File 'lib/ast/merge/layout/augmenter.rb', line 49 def gaps [preamble_gap, *interstitial_gaps, postlude_gap].compact end |