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.
5981 5982 5983 5984 |
# File 'lib/syntax_tree/node.rb', line 5981 def initialize(key, value) @key = key @value = value end |
Instance Attribute Details
#key ⇒ Object (readonly)
- Label
-
the keyword being used
5976 5977 5978 |
# File 'lib/syntax_tree/node.rb', line 5976 def key @key end |
#value ⇒ Object (readonly)
- Node
-
the optional value for the keyword
5979 5980 5981 |
# File 'lib/syntax_tree/node.rb', line 5979 def value @value end |
Instance Method Details
#comments ⇒ Object
5986 5987 5988 |
# File 'lib/syntax_tree/node.rb', line 5986 def comments [] end |
#format(q) ⇒ Object
5990 5991 5992 5993 5994 5995 5996 5997 |
# File 'lib/syntax_tree/node.rb', line 5990 def format(q) HashKeyFormatter::Labels.new.format_key(q, key) if value q.text(" ") q.format(value) end end |