Class: SyntaxTree::HshPtn::KeywordFormatter

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(key, value) ⇒ KeywordFormatter

Returns a new instance of KeywordFormatter.



6018
6019
6020
6021
# File 'lib/syntax_tree/node.rb', line 6018

def initialize(key, value)
  @key = key
  @value = value
end

Instance Attribute Details

#keyObject (readonly)

Label

the keyword being used



6013
6014
6015
# File 'lib/syntax_tree/node.rb', line 6013

def key
  @key
end

#valueObject (readonly)

Node

the optional value for the keyword



6016
6017
6018
# File 'lib/syntax_tree/node.rb', line 6016

def value
  @value
end

Instance Method Details

#commentsObject



6023
6024
6025
# File 'lib/syntax_tree/node.rb', line 6023

def comments
  []
end

#format(q) ⇒ Object



6027
6028
6029
6030
6031
6032
6033
6034
# File 'lib/syntax_tree/node.rb', line 6027

def format(q)
  HashKeyFormatter::Labels.new.format_key(q, key)

  if value
    q.text(" ")
    q.format(value)
  end
end