class Yalphabetize::OffenceDetector
Attributes
Public Class Methods
Source
# File lib/yalphabetize/offence_detector.rb, line 5 def initialize(stream_node, order_checker_class:) @stream_node = stream_node @order_checker_class = order_checker_class end
Public Instance Methods
Source
# File lib/yalphabetize/offence_detector.rb, line 10 def offences? !alphabetized?(stream_node) end
Private Instance Methods
Source
# File lib/yalphabetize/offence_detector.rb, line 18 def alphabetized?(node) return false if node.mapping? && !alphabetized_children?(node) if node.children each_child_also_alphabetized?(node.children) else true end end
Source
# File lib/yalphabetize/offence_detector.rb, line 28 def alphabetized_children?(node) order_checker = order_checker_class.new_for(node) node.children.each_slice(2).each_cons(2).all? do |a, b| order_checker.ordered?(a.first.value, b.first.value) end end
Source
# File lib/yalphabetize/offence_detector.rb, line 36 def each_child_also_alphabetized?(children) children.flatten&.inject(true) { |bool, child_node| bool && alphabetized?(child_node) } end