Class: SyntaxTree::ConditionalModFormatter
- Inherits:
-
Object
- Object
- SyntaxTree::ConditionalModFormatter
- Defined in:
- lib/syntax_tree.rb
Overview
Formats an IfMod or UnlessMod node.
Instance Attribute Summary collapse
-
#keyword ⇒ Object
readonly
- String
-
the keyword associated with this conditional.
-
#node ⇒ Object
readonly
- IfMod | UnlessMod
-
the node that is being formatted.
Instance Method Summary collapse
- #format(q) ⇒ Object
-
#initialize(keyword, node) ⇒ ConditionalModFormatter
constructor
A new instance of ConditionalModFormatter.
Constructor Details
#initialize(keyword, node) ⇒ ConditionalModFormatter
Returns a new instance of ConditionalModFormatter.
6689 6690 6691 6692 |
# File 'lib/syntax_tree.rb', line 6689 def initialize(keyword, node) @keyword = keyword @node = node end |
Instance Attribute Details
#keyword ⇒ Object (readonly)
- String
-
the keyword associated with this conditional
6684 6685 6686 |
# File 'lib/syntax_tree.rb', line 6684 def keyword @keyword end |
#node ⇒ Object (readonly)
- IfMod | UnlessMod
-
the node that is being formatted
6687 6688 6689 |
# File 'lib/syntax_tree.rb', line 6687 def node @node end |
Instance Method Details
#format(q) ⇒ Object
6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 |
# File 'lib/syntax_tree.rb', line 6694 def format(q) q.group do q.if_break do q.text("#{keyword} ") q.nest(keyword.length + 1) { q.format(node.predicate) } q.indent do q.breakable q.format(node.statement) end q.breakable q.text("end") end.if_flat do q.format(node.statement) q.text(" #{keyword} ") q.format(node.predicate) end end end |