Class: RuboCop::Cop::Style::AlignHash::AlignmentOfValues

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/cop/style/align_hash.rb

Overview

Common functionality for the styles where not only keys, but also values are aligned.

Direct Known Subclasses

SeparatorAlignment, TableAlignment

Instance Method Summary collapse

Instance Method Details

#checkable_layout(node) ⇒ Object


34
35
36
# File 'lib/rubocop/cop/style/align_hash.rb', line 34

def checkable_layout(node)
  !any_pairs_on_the_same_line?(node) && all_have_same_sparator?(node)
end

#deltas(first_pair, _prev_pair, current_pair) ⇒ Object


38
39
40
41
42
43
44
45
46
47
# File 'lib/rubocop/cop/style/align_hash.rb', line 38

def deltas(first_pair, _prev_pair, current_pair)
  key_delta = key_delta(first_pair, current_pair)
  current_separator = current_pair.loc.operator
  separator_delta = separator_delta(first_pair, current_separator,
                                    key_delta)
  value_delta = value_delta(first_pair, current_pair) -
                key_delta - separator_delta

  { key: key_delta, separator: separator_delta, value: value_delta }
end