Class: CSSPool::Selector

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Node

#==, #accept, #children, #each, #hash, #to_css, #to_minified_css

Constructor Details

#initialize(simple_selectors = [], parse_location = {}) ⇒ Selector

Returns a new instance of Selector.



7
8
9
10
11
# File 'lib/csspool/selector.rb', line 7

def initialize simple_selectors = [], parse_location = {}
  @simple_selectors = simple_selectors
  @parse_location   = parse_location
  @rule_set         = nil
end

Instance Attribute Details

#parse_locationObject

Returns the value of attribute parse_location.



4
5
6
# File 'lib/csspool/selector.rb', line 4

def parse_location
  @parse_location
end

#rule_setObject

Returns the value of attribute rule_set.



5
6
7
# File 'lib/csspool/selector.rb', line 5

def rule_set
  @rule_set
end

#simple_selectorsObject

Returns the value of attribute simple_selectors.



3
4
5
# File 'lib/csspool/selector.rb', line 3

def simple_selectors
  @simple_selectors
end

Instance Method Details

#declarationsObject



13
14
15
# File 'lib/csspool/selector.rb', line 13

def declarations
  @rule_set.declarations
end

#specificityObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/csspool/selector.rb', line 17

def specificity
  a = b = c = 0
  simple_selectors.each do |s|
    if !s.name.nil?
      c += 1
    end
    s.additional_selectors.each do |additional_selector|
      if Selectors::Id === additional_selector
        a += 1
      elsif Selectors::PseudoElement === additional_selector
        c += 1
      else
        b += 1
      end
    end
  end
  [a, b, c]
end