Class: RuboCop::Cop::HashAlignment::TableAlignment

Inherits:
Object
  • Object
show all
Includes:
ValueAlignment
Defined in:
lib/rubocop/cop/mixin/hash_alignment.rb

Overview

Handles calculation of deltas when the enforced style is 'table'.

Instance Method Summary collapse

Methods included from ValueAlignment

#checkable_layout?, #deltas

Constructor Details

#initializeTableAlignment

Returns a new instance of TableAlignment


86
87
88
# File 'lib/rubocop/cop/mixin/hash_alignment.rb', line 86

def initialize
  self.max_key_width = 0
end

Instance Method Details

#deltas_for_first_pair(first_pair, node) ⇒ Object


90
91
92
93
94
95
96
97
98
# File 'lib/rubocop/cop/mixin/hash_alignment.rb', line 90

def deltas_for_first_pair(first_pair, node)
  self.max_key_width = node.keys.map { |key| key.source.length }.max

  separator_delta = separator_delta(first_pair, first_pair, 0)
  {
    separator: separator_delta,
    value: value_delta(first_pair, first_pair) - separator_delta
  }
end