Class: BeautifulCss::Rule

Inherits:
Object
  • Object
show all
Defined in:
lib/beautiful-css/rule.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#propObject

Returns the value of attribute prop.



4
5
6
# File 'lib/beautiful-css/rule.rb', line 4

def prop
  @prop
end

#selectorObject

Returns the value of attribute selector.



4
5
6
# File 'lib/beautiful-css/rule.rb', line 4

def selector
  @selector
end

#valueObject

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_sObject



19
20
21
# File 'lib/beautiful-css/rule.rb', line 19

def to_s
  @selector + "\n" + "{ #{prop}:#{value} }"
end