Class: BeautifulCss::Rule
- Inherits:
-
Object
- Object
- BeautifulCss::Rule
- Defined in:
- lib/beautiful-css/rule.rb
Instance Attribute Summary collapse
-
#prop ⇒ Object
Returns the value of attribute prop.
-
#selector ⇒ Object
Returns the value of attribute selector.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #cleaner(sel) ⇒ Object
-
#initialize(selector, prop, value) ⇒ Rule
constructor
A new instance of Rule.
- #to_s ⇒ Object
Constructor Details
#initialize(selector, prop, value) ⇒ Rule
Returns a new instance of Rule.
6 7 8 |
# File 'lib/beautiful-css/rule.rb', line 6 def initialize(selector, prop, value) @selector, @prop, @value = cleaner(selector), (prop || '').downcase, value end |
Instance Attribute Details
#prop ⇒ Object
Returns the value of attribute prop.
4 5 6 |
# File 'lib/beautiful-css/rule.rb', line 4 def prop @prop end |
#selector ⇒ Object
Returns the value of attribute selector.
4 5 6 |
# File 'lib/beautiful-css/rule.rb', line 4 def selector @selector end |
#value ⇒ Object
Returns the value of attribute value.
4 5 6 |
# File 'lib/beautiful-css/rule.rb', line 4 def value @value end |
Instance Method Details
#cleaner(sel) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/beautiful-css/rule.rb', line 10 def cleaner sel sel.to_s.split(' ').map do |part| #only tags are case insensitive tag = part.split(/\.|#/)[0] to_replace = Regexp.new("^"+ tag) part.gsub to_replace, tag.downcase end.join(' ') end |
#to_s ⇒ Object
19 20 21 |
# File 'lib/beautiful-css/rule.rb', line 19 def to_s @selector + "\n" + "{ #{prop}:#{value} }" end |