Class: SyntaxTree::HshPtn::KeywordFormatter
- Inherits:
-
Object
- Object
- SyntaxTree::HshPtn::KeywordFormatter
- Defined in:
- lib/syntax_tree/node.rb
Overview
Formats a key-value pair in a hash pattern. The value is optional.
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
- Label
-
the keyword being used.
-
#value ⇒ Object
readonly
- Node
-
the optional value for the keyword.
Instance Method Summary collapse
- #comments ⇒ Object
- #format(q) ⇒ Object
-
#initialize(key, value) ⇒ KeywordFormatter
constructor
A new instance of KeywordFormatter.
Constructor Details
#initialize(key, value) ⇒ KeywordFormatter
Returns a new instance of KeywordFormatter.
6000 6001 6002 6003 |
# File 'lib/syntax_tree/node.rb', line 6000 def initialize(key, value) @key = key @value = value end |
Instance Attribute Details
#key ⇒ Object (readonly)
- Label
-
the keyword being used
5995 5996 5997 |
# File 'lib/syntax_tree/node.rb', line 5995 def key @key end |
#value ⇒ Object (readonly)
- Node
-
the optional value for the keyword
5998 5999 6000 |
# File 'lib/syntax_tree/node.rb', line 5998 def value @value end |
Instance Method Details
#comments ⇒ Object
6005 6006 6007 |
# File 'lib/syntax_tree/node.rb', line 6005 def comments [] end |
#format(q) ⇒ Object
6009 6010 6011 6012 6013 6014 6015 6016 |
# File 'lib/syntax_tree/node.rb', line 6009 def format(q) HashKeyFormatter::Labels.new.format_key(q, key) if value q.text(" ") q.format(value) end end |