Parent

Included Modules

Files

Less::Node::Color

rgb(255, 0, 0) #

Attributes

r[R]
g[R]
b[R]
a[R]

Public Class Methods

new(r, g, b, a = 1.0) click to toggle source
    # File lib/less/engine/nodes/literal.rb, line 18
18:       def initialize r, g, b, a = 1.0
19:         @r, @g, @b = [r, g, b].map do |c|
20:           normalize(c.is_a?(String) ? c.to_i(16) : c)
21:         end
22:         @a = normalize(a, 1.0)
23:       end

Public Instance Methods

*(other;) click to toggle source
    # File lib/less/engine/nodes/literal.rb, line 44
44:       def * other; operate :*, other end
+(other;) click to toggle source
    # File lib/less/engine/nodes/literal.rb, line 42
42:       def + other; operate :+, other end
-(other;) click to toggle source
    # File lib/less/engine/nodes/literal.rb, line 43
43:       def - other; operate :-, other end
/(other;) click to toggle source
    # File lib/less/engine/nodes/literal.rb, line 45
45:       def / other; operate :/, other end
alpha(v) click to toggle source
    # File lib/less/engine/nodes/literal.rb, line 25
25:       def alpha v
26:         self.class.new r, g, b, v
27:       end
coerce(other) click to toggle source
    # File lib/less/engine/nodes/literal.rb, line 47
47:       def coerce other
48:         return self, other
49:       end
inspect() click to toggle source
    # File lib/less/engine/nodes/literal.rb, line 59
59:       def inspect
60:         if a < 1.0
61:           "rgba(#{r}, #{g}, #{b}, #{a})"
62:         else
63:           "rgb(#{r}, #{g}, #{b})"
64:         end
65:       end
operate(op, other) click to toggle source
    # File lib/less/engine/nodes/literal.rb, line 33
33:       def operate op, other
34:         color = if other.is_a? Numeric
35:           rgb.map {|c| c.send(op, other) }
36:         else
37:           rgb.zip(other.rgb).map {|a, b| a.send(op, b) }
38:         end
39:         self.class.new *[color, @a].flatten # Ruby 1.8 hack
40:       end
rgb() click to toggle source
    # File lib/less/engine/nodes/literal.rb, line 29
29:       def rgb
30:         [r, g, b]
31:       end
to_css() click to toggle source
    # File lib/less/engine/nodes/literal.rb, line 67
67:       def to_css
68:         to_s
69:       end
to_ruby() click to toggle source
    # File lib/less/engine/nodes/literal.rb, line 71
71:       def to_ruby
72:         "#{self.class}.new(#{r},#{g},#{b},#{a})"
73:       end
to_s() click to toggle source
    # File lib/less/engine/nodes/literal.rb, line 51
51:       def to_s
52:         if a < 1.0
53:           "rgba(#{r.to_i}, #{g.to_i}, #{b.to_i}, #{a})"
54:         else
55:           "#%02x%02x%02x" % [r, g, b]
56:         end
57:       end

Protected Instance Methods

normalize(v, max = 255, min = 0) click to toggle source
    # File lib/less/engine/nodes/literal.rb, line 76
76:       def normalize(v, max = 255, min = 0)
77:         [[min, v].max, max].min
78:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.