Class: MiniCSS::AST::Rule

Inherits:
Object
  • Object
show all
Defined in:
lib/minicss/ast/rule.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(struct) ⇒ Rule

Returns a new instance of Rule.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/minicss/ast/rule.rb', line 8

def initialize(struct)
  raise "Expected CSS::AST::QualifiedRule, found #{struct.class}" unless struct.is_a? CSS::AST::QualifiedRule

  @raw_selector = struct.prelude.map(&:literal).join
  begin
    @selector = Sel.parse(raw_selector)
    @valid_selector = true
  rescue StandardError => e
    pos = struct.prelude.first.pos_start
    @selector = "Failed parsing selector at #{pos.line}:#{pos.column}: #{e}"
    @valid_selector = false
  end

  @child_rules = struct.child_rules.map { AST.convert(it) }
  @decls = struct.decls.map { AST.convert(it) }
end

Instance Attribute Details

#child_rulesObject

Returns the value of attribute child_rules.



6
7
8
# File 'lib/minicss/ast/rule.rb', line 6

def child_rules
  @child_rules
end

#declsObject

Returns the value of attribute decls.



6
7
8
# File 'lib/minicss/ast/rule.rb', line 6

def decls
  @decls
end

#raw_selectorObject

Returns the value of attribute raw_selector.



6
7
8
# File 'lib/minicss/ast/rule.rb', line 6

def raw_selector
  @raw_selector
end

#selectorObject

Returns the value of attribute selector.



6
7
8
# File 'lib/minicss/ast/rule.rb', line 6

def selector
  @selector
end

Instance Method Details

#valid_selector?Boolean

Returns:

  • (Boolean)


25
# File 'lib/minicss/ast/rule.rb', line 25

def valid_selector? = @valid_selector