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.
5950 5951 5952 5953 |
# File 'lib/syntax_tree/node.rb', line 5950 def initialize(key, value) @key = key @value = value end |
Instance Attribute Details
#key ⇒ Object (readonly)
- Label
-
the keyword being used
5945 5946 5947 |
# File 'lib/syntax_tree/node.rb', line 5945 def key @key end |
#value ⇒ Object (readonly)
- Node
-
the optional value for the keyword
5948 5949 5950 |
# File 'lib/syntax_tree/node.rb', line 5948 def value @value end |
Instance Method Details
#comments ⇒ Object
5955 5956 5957 |
# File 'lib/syntax_tree/node.rb', line 5955 def comments [] end |
#format(q) ⇒ Object
5959 5960 5961 5962 5963 5964 5965 5966 |
# File 'lib/syntax_tree/node.rb', line 5959 def format(q) HashKeyFormatter::Labels.new.format_key(q, key) if value q.text(" ") q.format(value) end end |