Class: CSSPool::Selector

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

Instance Attribute Summary collapse

Attributes inherited from Node

#inner_end_pos, #inner_start_pos, #outer_end_pos, #outer_start_pos

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
35
# File 'lib/csspool/selector.rb', line 17

def specificity
  a = b = c = 0
  simple_selectors.each do |s|
    if s.is_a?(Selectors::Type) && s.name && s.name != ''
      c += 1
    end
    s.additional_selectors.each do |additional_selector|
      case additional_selector
      when Selectors::Id
        a += 1
      when Selectors::PseudoElement
        c += 1
      when Selectors::Class, Selectors::PseudoClass, Selectors::Attribute
        b += 1
      end
    end
  end
  [a, b, c]
end