Class: Glimmer::CSS::Rule

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

Direct Known Subclasses

MediaQuery

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CssFragment

#to_s

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

#propertiesObject (readonly)

Returns the value of attribute properties.



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

def properties
  @properties
end

#selectorObject (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_cssObject



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