Class: AjaxfulRating::CSSBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/axr/css_builder.rb

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (CSSBuilder) initialize



5
6
7
# File 'lib/axr/css_builder.rb', line 5

def initialize
  @rules = {}
end

Instance Attribute Details

- (Object) rules (readonly)

Returns the value of attribute rules



3
4
5
# File 'lib/axr/css_builder.rb', line 3

def rules
  @rules
end

Class Method Details

+ (Object) stringify_properties(properties)



21
22
23
24
25
26
27
28
# File 'lib/axr/css_builder.rb', line 21

def self.stringify_properties(properties)
  css = ''
  properties.each do |key, value|
    value = value.is_a?(Fixnum) || value.is_a?(Float) ? "#{value}px" : value
    css << "#{key.to_s.underscore.dasherize}: #{value}; "
  end
  css
end

Instance Method Details

- (Object) rule(selector, attrs)



9
10
11
# File 'lib/axr/css_builder.rb', line 9

def rule(selector, attrs)        
  @rules[selector] = self.class.stringify_properties(attrs) unless @rules.has_key?(selector)
end

- (Object) to_css



13
14
15
16
17
18
19
# File 'lib/axr/css_builder.rb', line 13

def to_css
  css = ''
  @rules.each do |key, value|
    css << "#{key} {#{value}}\n"
  end
  css
end