Class: Glimmer::CSS::Rule

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(selector) ⇒ Rule

Returns a new instance of Rule.



27
28
29
30
# File 'lib/glimmer/css/rule.rb', line 27

def initialize(selector)
  @selector = selector
  @properties = {}
end

Instance Attribute Details

#propertiesObject (readonly)

Returns the value of attribute properties.



25
26
27
# File 'lib/glimmer/css/rule.rb', line 25

def properties
  @properties
end

#selectorObject (readonly)

Returns the value of attribute selector.



25
26
27
# File 'lib/glimmer/css/rule.rb', line 25

def selector
  @selector
end

Instance Method Details

#add_property(keyword, *args) ⇒ Object



32
33
34
35
# File 'lib/glimmer/css/rule.rb', line 32

def add_property(keyword, *args)
  keyword = keyword.to_s.downcase.gsub('_', '-')
  @properties[keyword] = args.first
end

#to_cssObject Also known as: to_s



37
38
39
40
41
42
43
44
# File 'lib/glimmer/css/rule.rb', line 37

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