Class: StyleSheet
- Inherits:
-
Object
- Object
- StyleSheet
- Defined in:
- lib/csspress/style_sheet.rb
Overview
StyleSheet is a container class for Rule objects which can be added individually using the .add() method. The Rule objects that StyleSheet contains can be accessed using the .each_rule(){} method which yields each Rule to the block.
Example:
ss = StyleSheet.new
ss.add( Rule.new("A Rule") )
tb = TemplateBuilder.new ( ss )
puts tb.publish # output compressed version of ss
Instance Method Summary collapse
-
#add(rule) ⇒ Object
Add rule to StyleSheet Raises ArgumentError rule is not a Rule.
-
#each_rule ⇒ Object
Iterate through all rules in self and yield them to a block.
-
#initialize ⇒ StyleSheet
constructor
A new instance of StyleSheet.
-
#rules ⇒ Object
Return an array of all rules in self.
-
#size ⇒ Object
The number of rules in self.
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ StyleSheet
Returns a new instance of StyleSheet.
23 24 25 26 |
# File 'lib/csspress/style_sheet.rb', line 23 def initialize # Store style rules in order @rules = [] end |
Instance Method Details
#add(rule) ⇒ Object
Add rule to StyleSheet Raises ArgumentError rule is not a Rule
30 31 32 33 34 |
# File 'lib/csspress/style_sheet.rb', line 30 def add(rule) raise ArgumentError unless rule.instance_of?(Rule) @rules << rule @self end |
#each_rule ⇒ Object
Iterate through all rules in self and yield them to a block
43 44 45 |
# File 'lib/csspress/style_sheet.rb', line 43 def each_rule @rules.each {|r| yield r } end |
#rules ⇒ Object
Return an array of all rules in self
48 49 50 |
# File 'lib/csspress/style_sheet.rb', line 48 def rules @rules.dup end |
#size ⇒ Object
The number of rules in self
37 38 39 |
# File 'lib/csspress/style_sheet.rb', line 37 def size @rules.size end |
#to_s ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/csspress/style_sheet.rb', line 52 def to_s out = "" @rules.each do |rule| out << rule.to_s end out end |