Class: Ast::Merge::Layout::Policy
- Inherits:
-
Object
- Object
- Ast::Merge::Layout::Policy
- Defined in:
- lib/ast/merge/layout/policy.rb
Overview
Named layout policy for whitespace comparison/rendering decisions.
Constant Summary collapse
- PRESERVE_EXACT =
:preserve_exact- BLANK_LINE_EQUIVALENT =
:blank_line_equivalent- MODES =
[PRESERVE_EXACT, BLANK_LINE_EQUIVALENT].freeze
Instance Attribute Summary collapse
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
Instance Method Summary collapse
- #blank_line_equivalent? ⇒ Boolean
- #equivalent_blank_line?(left, right) ⇒ Boolean
-
#initialize(mode: PRESERVE_EXACT, metadata: {}, **options) ⇒ Policy
constructor
A new instance of Policy.
- #preserve_exact? ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(mode: PRESERVE_EXACT, metadata: {}, **options) ⇒ Policy
Returns a new instance of Policy.
14 15 16 17 |
# File 'lib/ast/merge/layout/policy.rb', line 14 def initialize(mode: PRESERVE_EXACT, metadata: {}, **) @mode = normalize_mode(mode) @metadata = .merge().freeze end |
Instance Attribute Details
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
12 13 14 |
# File 'lib/ast/merge/layout/policy.rb', line 12 def @metadata end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
12 13 14 |
# File 'lib/ast/merge/layout/policy.rb', line 12 def mode @mode end |
Instance Method Details
#blank_line_equivalent? ⇒ Boolean
23 24 25 |
# File 'lib/ast/merge/layout/policy.rb', line 23 def blank_line_equivalent? mode == BLANK_LINE_EQUIVALENT end |
#equivalent_blank_line?(left, right) ⇒ Boolean
27 28 29 30 31 32 33 |
# File 'lib/ast/merge/layout/policy.rb', line 27 def equivalent_blank_line?(left, right) if blank_line_equivalent? blank_line?(left) && blank_line?(right) else left == right end end |
#preserve_exact? ⇒ Boolean
19 20 21 |
# File 'lib/ast/merge/layout/policy.rb', line 19 def preserve_exact? mode == PRESERVE_EXACT end |
#to_h ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/ast/merge/layout/policy.rb', line 35 def to_h { mode: mode, metadata: , exact_preservation: preserve_exact?, blank_line_equivalence: blank_line_equivalent? } end |