class RubbyCop::AST::HashElementNode::HashElementDelta
A helper class for comparing the positions of different parts of a `pair` node.
Attributes
first[R]
second[R]
Public Class Methods
new(first, second)
click to toggle source
# File lib/rubbycop/ast/node/mixin/hash_element_node.rb, line 68 def initialize(first, second) @first = first @second = second raise ArgumentError unless valid_argument_types? end
Public Instance Methods
delimiter_delta()
click to toggle source
# File lib/rubbycop/ast/node/mixin/hash_element_node.rb, line 89 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
key_delta(alignment = :left)
click to toggle source
# File lib/rubbycop/ast/node/mixin/hash_element_node.rb, line 75 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
value_delta()
click to toggle source
# File lib/rubbycop/ast/node/mixin/hash_element_node.rb, line 82 def value_delta return 0 if first.same_line?(second) return 0 if keyword_splat? delta(first.value.loc, second.value.loc) end
Private Instance Methods
delta(first, second, alignment = :left)
click to toggle source
# File lib/rubbycop/ast/node/mixin/hash_element_node.rb, line 106 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
keyword_splat?()
click to toggle source
# File lib/rubbycop/ast/node/mixin/hash_element_node.rb, line 117 def keyword_splat? [first, second].any?(&:kwsplat_type?) end
valid_argument_types?()
click to toggle source
# File lib/rubbycop/ast/node/mixin/hash_element_node.rb, line 100 def valid_argument_types? [first, second].all? do |argument| argument.pair_type? || argument.kwsplat_type? end end