Class: CSSPool::Selector

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

Constant Summary collapse

COMBINATORS =
[nil, ' ', ' + ', ' > ']

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Visitable

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

Constructor Details

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

Returns a new instance of Selector.



10
11
12
13
14
# File 'lib/csspool/selector.rb', line 10

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



16
17
18
# File 'lib/csspool/selector.rb', line 16

def declarations
  @rule_set.declarations
end

#specificityObject



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

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