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.



6000
6001
6002
6003
# File 'lib/syntax_tree/node.rb', line 6000

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

Instance Attribute Details

#keyObject (readonly)

Label

the keyword being used



5995
5996
5997
# File 'lib/syntax_tree/node.rb', line 5995

def key
  @key
end

#valueObject (readonly)

Node

the optional value for the keyword



5998
5999
6000
# File 'lib/syntax_tree/node.rb', line 5998

def value
  @value
end

Instance Method Details

#commentsObject



6005
6006
6007
# File 'lib/syntax_tree/node.rb', line 6005

def comments
  []
end

#format(q) ⇒ Object



6009
6010
6011
6012
6013
6014
6015
6016
# File 'lib/syntax_tree/node.rb', line 6009

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

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