Class: ColorParser::Stylesheet

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

Instance Method Summary collapse

Constructor Details

#initialize(style_sheet) ⇒ Stylesheet

Returns a new instance of Stylesheet.



5
6
7
# File 'lib/color_parser/stylesheet.rb', line 5

def initialize(style_sheet)
  @style_sheet = style_sheet
end

Instance Method Details

#bg_colorsObject



14
15
16
# File 'lib/color_parser/stylesheet.rb', line 14

def bg_colors
  @bg_colors ||= parse_colors(bg_properties)
end

#border_colorsObject



22
23
24
# File 'lib/color_parser/stylesheet.rb', line 22

def border_colors
  @border_colors ||= parse_colors(border_properties)
end

#colorsObject

gst list of colors from styles



10
11
12
# File 'lib/color_parser/stylesheet.rb', line 10

def colors
  @colors ||= parse_colors(color_properties)
end

#propertiesObject

split up selectors into properties, and return property key/value pairs



40
41
42
43
44
45
46
47
48
# File 'lib/color_parser/stylesheet.rb', line 40

def properties
  properties = []

  rules.values.each do |declarations|
    declarations.each {|property, value| properties << [property, value] }
  end
  
  properties
end

#rulesObject



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/color_parser/stylesheet.rb', line 26

def rules
  rules = {}
  
  ([@style_sheet] + style_sheets).each do |css|
    css.style_rules.each do |rule|
      rules[rule.selector_text] ||= {}
      rules[rule.selector_text].merge!(rule.style.declarations)
    end
  end

  rules
end

#text_colorsObject



18
19
20
# File 'lib/color_parser/stylesheet.rb', line 18

def text_colors
  @text_colors ||= parse_colors(text_properties)
end