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.



5981
5982
5983
5984
# File 'lib/syntax_tree/node.rb', line 5981

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

Instance Attribute Details

#keyObject (readonly)

Label

the keyword being used



5976
5977
5978
# File 'lib/syntax_tree/node.rb', line 5976

def key
  @key
end

#valueObject (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

#commentsObject



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