Class: InlineStyle::Rule

Inherits:
Object
  • Object
show all
Defined in:
lib/inline-style/rule.rb

Overview

A simple abstraction of the data we get back from the parsers. CSSPool actually already does this for us but CSSParser does not so we need to create the abstraction ourselves.

Constant Summary collapse

DYNAMIC_PSEUDO_CLASSES =
%w(link visited active hover focus target enabled disabled checked)
DYNAMIC_PSEUDO_CLASSES_MATCHER =
/:(#{DYNAMIC_PSEUDO_CLASSES.join('|')})$/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(selector, declarations, specificity) ⇒ Rule

Returns a new instance of Rule.



11
12
13
14
15
16
# File 'lib/inline-style/rule.rb', line 11

def initialize selector, declarations, specificity
  @specificity = specificity
  @selector, @dynamic_pseudo_class = selector.split DYNAMIC_PSEUDO_CLASSES_MATCHER
  @selector.sub! /$^/, '*'
  @declarations = declarations.scan /\s*([^:]+):\s*([^;]+);/
end

Instance Attribute Details

#declarationsObject (readonly)

Returns the value of attribute declarations.



9
10
11
# File 'lib/inline-style/rule.rb', line 9

def declarations
  @declarations
end

#dynamic_pseudo_classObject (readonly)

Returns the value of attribute dynamic_pseudo_class.



9
10
11
# File 'lib/inline-style/rule.rb', line 9

def dynamic_pseudo_class
  @dynamic_pseudo_class
end

#selectorObject (readonly)

Returns the value of attribute selector.



9
10
11
# File 'lib/inline-style/rule.rb', line 9

def selector
  @selector
end

#specificityObject (readonly)

Returns the value of attribute specificity.



9
10
11
# File 'lib/inline-style/rule.rb', line 9

def specificity
  @specificity
end