class RuboCop::Cop::Style::AlignHash::TableAlignment
Handles calculation of deltas when the enforced style is ‘table’.
def deltas_for_first_pair(first_pair, node)
The table style is the only one where the first key-value pair can
def deltas_for_first_pair(first_pair, node) key_widths = node.children.map do |pair| key, _value = *pair key.source.length end @max_key_width = key_widths.max separator_delta = separator_delta(first_pair, first_pair.loc.operator, 0) { separator: separator_delta, value: value_delta(first_pair, first_pair) - separator_delta } end
def hash_rocket_delta(first_pair, current_separator)
def hash_rocket_delta(first_pair, current_separator) first_pair.loc.column + @max_key_width + 1 - current_separator.column end
def key_delta(first_pair, current_pair)
def key_delta(first_pair, current_pair) first_pair.loc.column - current_pair.loc.column end
def spaced_separator(node)
def spaced_separator(node) node.loc.operator.is?('=>') ? ' => ' : ': ' end
def value_delta(first_pair, current_pair)
def value_delta(first_pair, current_pair) first_key, = *first_pair _, current_value = *current_pair correct_value_column = first_key.loc.column + spaced_separator(current_pair).length + @max_key_width correct_value_column - current_value.loc.column end