class RuboCop::AST::HashElementNode::HashElementDelta
‘pair` node.
A helper class for comparing the positions of different parts of a
def delimiter_delta
def delimiter_delta return 0 if first.same_line?(second) return 0 if first.delimiter != second.delimiter delta(first.loc.operator, second.loc.operator) end
def delta(first, second, alignment = :left)
def delta(first, second, alignment = :left) case alignment when :left first.column - second.column when :right first.last_column - second.last_column else 0 end end
def initialize(first, second)
def initialize(first, second) @first = first @second = second raise ArgumentError unless valid_argument_types? end
def key_delta(alignment = :left)
def key_delta(alignment = :left) return 0 if first.same_line?(second) return 0 if keyword_splat? && alignment == :right delta(first.key.loc, second.key.loc, alignment) end
def keyword_splat?
def keyword_splat? [first, second].any?(&:kwsplat_type?) end
def valid_argument_types?
def valid_argument_types? [first, second].all? do |argument| argument.pair_type? || argument.kwsplat_type? end end
def value_delta
def value_delta return 0 if first.same_line?(second) return 0 if keyword_splat? delta(first.value.loc, second.value.loc) end