Class: Glimmer::CSS::Rule

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

Direct Known Subclasses

MediaQuery

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(selector, parent:) ⇒ Rule

Returns a new instance of Rule.



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

def initialize(selector, parent:)
  @selector = selector
  @properties = {}
  @parent = parent
  parent.rules << self
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



34
35
36
37
# File 'lib/glimmer/css/rule.rb', line 34

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

#to_cssObject Also known as: to_s



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

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