Class: Rule
- Inherits:
-
Object
- Object
- Rule
- Defined in:
- lib/csspress/rule.rb
Overview
Rule represents a rule in a style sheet. An example of a rule would be:
body { margin : 0; padding : 0 }
The components of a rule are:
name { declarations }
All declarations of Rule can be accessed using the .each_declaration(){} method where each declaration is passed to the block as a Declaration object.
Example:
r = Rule.new ( "foo { margin: 0; padding: 0 }" )
r.each_declaration do |dec|
puts dec
end
puts r.name
Defined Under Namespace
Classes: RuleParser
Instance Attribute Summary collapse
-
#declarations ⇒ Object
readonly
declarations contained within Rule.
-
#name ⇒ Object
readonly
name of the Rule.
Instance Method Summary collapse
-
#each_declaration ⇒ Object
Yeild all declarations for self.
-
#initialize(string) ⇒ Rule
constructor
Create a new Rule from a string (The string should be a valid CSS rule!).
-
#to_s ⇒ Object
Print out the rule neatly.
Constructor Details
#initialize(string) ⇒ Rule
Create a new Rule from a string (The string should be a valid CSS rule!)
38 39 40 41 42 |
# File 'lib/csspress/rule.rb', line 38 def initialize( string ) rp = RuleParser.new( string ) @name = rp.name @declarations = rp.declarations end |
Instance Attribute Details
#declarations ⇒ Object (readonly)
declarations contained within Rule
33 34 35 |
# File 'lib/csspress/rule.rb', line 33 def declarations @declarations end |
#name ⇒ Object (readonly)
name of the Rule
31 32 33 |
# File 'lib/csspress/rule.rb', line 31 def name @name end |
Instance Method Details
#each_declaration ⇒ Object
Yeild all declarations for self
46 47 48 49 50 |
# File 'lib/csspress/rule.rb', line 46 def each_declaration @declarations.each do |declaration| yield declaration end end |
#to_s ⇒ Object
Print out the rule neatly
54 55 56 |
# File 'lib/csspress/rule.rb', line 54 def to_s "#{@name}{#{@declarations.join(";")}}" end |