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.
6003 6004 6005 6006 |
# File 'lib/syntax_tree/node.rb', line 6003 def initialize(key, value) @key = key @value = value end |
Instance Attribute Details
#key ⇒ Object (readonly)
- Label
-
the keyword being used
5998 5999 6000 |
# File 'lib/syntax_tree/node.rb', line 5998 def key @key end |
#value ⇒ Object (readonly)
- Node
-
the optional value for the keyword
6001 6002 6003 |
# File 'lib/syntax_tree/node.rb', line 6001 def value @value end |
Instance Method Details
#comments ⇒ Object
6008 6009 6010 |
# File 'lib/syntax_tree/node.rb', line 6008 def comments [] end |
#format(q) ⇒ Object
6012 6013 6014 6015 6016 6017 6018 6019 |
# File 'lib/syntax_tree/node.rb', line 6012 def format(q) HashKeyFormatter::Labels.new.format_key(q, key) if value q.text(" ") q.format(value) end end |