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.



5950
5951
5952
5953
# File 'lib/syntax_tree/node.rb', line 5950

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

Instance Attribute Details

#keyObject (readonly)

Label

the keyword being used



5945
5946
5947
# File 'lib/syntax_tree/node.rb', line 5945

def key
  @key
end

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

#commentsObject



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