class StyleCop::SelectorDifference

Constants

EXTRA_CSS_TEXT
EXTRA_STRUCTURE_TEXT
MISSING_CSS_TEXT
MISSING_STRUCTURE_TEXT

Attributes

other_selector[R]
selector[R]

Public Class Methods

new(selector, other_selector) click to toggle source
# File lib/style_cop/selector_difference.rb, line 8
def initialize(selector, other_selector)
  @selector = selector
  @other_selector = other_selector
end

Public Instance Methods

empty?() click to toggle source
# File lib/style_cop/selector_difference.rb, line 13
def empty?
  selector.representation == other_selector.representation
end
error_message() click to toggle source
# File lib/style_cop/selector_difference.rb, line 17
def error_message
  (css_errors + structure_errors).join(", ")
end

Private Instance Methods

css_difference(selector1, selector2) click to toggle source
# File lib/style_cop/selector_difference.rb, line 45
def css_difference(selector1, selector2)
  difference = {}
  selector2_representation = selector2.representation
  selector1.representation.each do |path, selector1_css|
    if selector2_css = selector2_representation[path]
      difference[path] = Hash[selector2_css.to_a - selector1_css.to_a]
    end
  end
  difference
end
css_errors() click to toggle source
# File lib/style_cop/selector_difference.rb, line 34
def css_errors
  errors = []
  css_difference(other_selector, selector).each do |path, extra_css|
    errors << "The #{selector.key} #{EXTRA_CSS_TEXT}: #{extra_css.map{|k,v| "#{k}: #{v}"}.join(', ')}" unless extra_css.empty?
  end
  css_difference(selector, other_selector).each do |path, extra_css|
    errors << "The #{selector.key} #{MISSING_CSS_TEXT}: #{extra_css.map{|k,v| "#{k}: #{v}"}.join(', ')}" unless extra_css.empty?
  end
  errors
end
structure_errors() click to toggle source
# File lib/style_cop/selector_difference.rb, line 25
def structure_errors
  errors = []
  extra_elements = selector.representation.keys - other_selector.representation.keys
  missing_elements = other_selector.representation.keys - selector.representation.keys
  errors << "The #{selector.key} #{EXTRA_STRUCTURE_TEXT}: #{extra_elements.join(", ")}" if extra_elements.any?
  errors << "The #{selector.key} #{MISSING_STRUCTURE_TEXT}: #{missing_elements.join(", ")}" if missing_elements.any?
  errors
end