Class: SpreadsheetBuilder::CssRule
- Inherits:
-
Object
- Object
- SpreadsheetBuilder::CssRule
show all
- Defined in:
- lib/spreadsheet_builder/css_rule.rb
Instance Method Summary
collapse
Constructor Details
#initialize(rule) ⇒ CssRule
Returns a new instance of CssRule.
3
4
5
|
# File 'lib/spreadsheet_builder/css_rule.rb', line 3
def initialize(rule)
@rule = rule
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *attrs, &block) ⇒ Object
34
35
36
37
38
39
40
|
# File 'lib/spreadsheet_builder/css_rule.rb', line 34
def method_missing(method, *attrs, &block)
if @rule.respond_to?(method)
@rule.__send__(method, *attrs, &block)
else
super
end
end
|
Instance Method Details
#declarations ⇒ Object
7
8
9
|
# File 'lib/spreadsheet_builder/css_rule.rb', line 7
def declarations
@rule.instance_variable_get(:@declarations)
end
|
#find_selector(tree) ⇒ Object
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/spreadsheet_builder/css_rule.rb', line 22
def find_selector(tree)
selectors.find { |s|
next unless tree.last & s.last == s.last
s[0..-2].reverse.inject(tree.length - 2) do |i, s_node|
break false unless i
tree[0..i].index { |kt_node| kt_node & s_node == s_node }
end
}
end
|
#selectors ⇒ Object
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/spreadsheet_builder/css_rule.rb', line 11
def selectors
@rule.selectors.map { |s|
s = s.split(/[\s>]/).map { |node| node.split('.') }
s.each do |node|
n = node.length
node[1...n] = node[1...n].map { |k| '.' + k }
node.delete_if { |k| k.empty? || k == "." }
end
}.sort_by(&:length)
end
|