Class: Stylesheet::CssRule

Inherits:
Object
  • Object
show all
Defined in:
lib/stylesheet/css_rule.rb

Constant Summary collapse

NULL_RULE =
0
STYLE_RULE =
1
CHARSET_RULE =
2
IMPORT_RULE =
3
MEDIA_RULE =
4
FONT_FACE_RULE =
5

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ CssRule

Returns a new instance of CssRule.



33
34
35
36
37
38
# File 'lib/stylesheet/css_rule.rb', line 33

def initialize(args)
  @parent_style_sheet = args[:parent_style_sheet]
  @parent_rule        = args[:parent_rule]
  @css_text           = args[:css_text]
  parse_css_text
end

Class Attribute Details

.rule_classesObject (readonly)

Returns the value of attribute rule_classes.



16
17
18
# File 'lib/stylesheet/css_rule.rb', line 16

def rule_classes
  @rule_classes
end

Instance Attribute Details

#css_textObject (readonly)

Returns the value of attribute css_text.



11
12
13
# File 'lib/stylesheet/css_rule.rb', line 11

def css_text
  @css_text
end

#parent_ruleObject (readonly)

Returns the value of attribute parent_rule.



11
12
13
# File 'lib/stylesheet/css_rule.rb', line 11

def parent_rule
  @parent_rule
end

#parent_style_sheetObject (readonly)

Returns the value of attribute parent_style_sheet.



11
12
13
# File 'lib/stylesheet/css_rule.rb', line 11

def parent_style_sheet
  @parent_style_sheet
end

#typeObject



40
41
42
# File 'lib/stylesheet/css_rule.rb', line 40

def type
  raise NotImplementedError
end

Class Method Details

.factory(args) ⇒ Object



25
26
27
28
29
30
# File 'lib/stylesheet/css_rule.rb', line 25

def self.factory(args)
  rule = CssRule.rule_classes.find do |klass| 
    klass.matches_rule?(args[:css_text])
  end
  rule.new(args) if rule
end

.inherited(subclass) ⇒ Object



21
22
23
# File 'lib/stylesheet/css_rule.rb', line 21

def self.inherited(subclass)
  CssRule.rule_classes << subclass
end

Instance Method Details

#matches_rule?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/stylesheet/css_rule.rb', line 44

def matches_rule?
  false
end

#to_sObject



48
49
50
# File 'lib/stylesheet/css_rule.rb', line 48

def to_s
  "#<#{self.class.name} css_text:#{css_text}>"
end