Class: CssParserMaster::Selector

Inherits:
Object
  • Object
show all
Includes:
DeclarationAPI
Defined in:
lib/css_parser_master/selector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DeclarationAPI

#add_declaration!, #each_declaration, #ensure_valid_declarations!, #parse_declarations!

Constructor Details

#initialize(selector, declarations, specificity) ⇒ Selector

Returns a new instance of Selector.



9
10
11
12
13
14
15
16
# File 'lib/css_parser_master/selector.rb', line 9

def initialize(selector, declarations, specificity)
  @selector = selector
  @order = 0     
  @declarations = {}
  parse_declarations!(declarations)  
  # puts "init @declarations: #{@declarations}"
  @specificity = specificity 
end

Instance Attribute Details

#declarationsObject

Returns the value of attribute declarations.



7
8
9
# File 'lib/css_parser_master/selector.rb', line 7

def declarations
  @declarations
end

#selectorObject

Returns the value of attribute selector.



7
8
9
# File 'lib/css_parser_master/selector.rb', line 7

def selector
  @selector
end

#specificityObject

Returns the value of attribute specificity.



7
8
9
# File 'lib/css_parser_master/selector.rb', line 7

def specificity
  @specificity
end

Instance Method Details

#declarations_to_s(options = {}) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/css_parser_master/selector.rb', line 18

def declarations_to_s(options = {})
  # puts "declarations_to_s: #{declarations.inspect}"
  s = declarations.map do |decl| 
    decl[1].to_text
  end.join('')
  # puts "res: #{s}"
  s
end

#to_textObject



28
29
30
# File 'lib/css_parser_master/selector.rb', line 28

def to_text
  "#{selector}\n{\n#{declarations_to_s}\n} \n"
end