Class: Glimmer::CSS::Rule
- Inherits:
-
Object
- Object
- Glimmer::CSS::Rule
- Includes:
- CssFragment
- Defined in:
- lib/glimmer/css/rule.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
-
#selector ⇒ Object
readonly
Returns the value of attribute selector.
Instance Method Summary collapse
- #add_property(keyword, *args) ⇒ Object
-
#initialize(selector, parent:) ⇒ Rule
constructor
A new instance of Rule.
- #to_css ⇒ Object
Methods included from CssFragment
Constructor Details
#initialize(selector, parent:) ⇒ Rule
Returns a new instance of Rule.
31 32 33 34 35 36 |
# File 'lib/glimmer/css/rule.rb', line 31 def initialize(selector, parent:) @selector = selector @properties = {} @parent = parent parent.children << self end |
Instance Attribute Details
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
29 30 31 |
# File 'lib/glimmer/css/rule.rb', line 29 def properties @properties end |
#selector ⇒ Object (readonly)
Returns the value of attribute selector.
29 30 31 |
# File 'lib/glimmer/css/rule.rb', line 29 def selector @selector end |
Instance Method Details
#add_property(keyword, *args) ⇒ Object
38 39 40 41 |
# File 'lib/glimmer/css/rule.rb', line 38 def add_property(keyword, *args) keyword = keyword.to_s.downcase.gsub('_', '-') @properties[keyword] = args.first end |
#to_css ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/glimmer/css/rule.rb', line 43 def to_css css = "#{@selector}{" css += @properties.map do |name, value| value = "#{value}px" if value.is_a?(Numeric) "#{name}:#{value}" end.join(';') css += "}" end |