Class: StyleCop::Selector

Inherits:
Object
  • Object
show all
Defined in:
lib/style_cop/selector.rb

Constant Summary collapse

EXCLUDED_KEYS =
[
  "width", "height", "top", "bottom", "right", "left",
  "-webkit-perspective-origin", "-webkit-transform-origin"
]

Instance Method Summary collapse

Constructor Details

#initialize(selector) ⇒ Selector

Returns a new instance of Selector.



8
9
10
# File 'lib/style_cop/selector.rb', line 8

def initialize(selector)
  @selector = selector
end

Instance Method Details

#keyObject



12
13
14
15
16
17
18
19
20
# File 'lib/style_cop/selector.rb', line 12

def key
  if selector['class']
    ".#{selector['class'].gsub(' ', '.')}"
  elsif selector['id']
    "##{selector['id']}"
  else
    selector.tag_name
  end
end

#representationObject



22
23
24
25
26
27
28
29
# File 'lib/style_cop/selector.rb', line 22

def representation
  clean_key = key.gsub(".style-cop-pattern", "")
  return { clean_key => computed_style } if children.empty?
  children_hash = children.map(&:representation).inject({}) { |hash, h| hash.merge!(h) }
  Hash[children_hash.map { |key, value| ["#{clean_key} #{key}", value] }].merge(
    clean_key => computed_style
  )
end