Class: Less::Node::Color

Inherits:
Fixnum
  • Object
show all
Includes:
Literal
Defined in:
lib/less/engine/nodes/literal.rb

Overview

rgb(255, 0, 0) #f0f0f0

Instance Attribute Summary collapse

Attributes included from Entity

#parent

Instance Method Summary collapse

Methods included from Entity

#path, #root

Constructor Details

#initialize(color = nil, opacity = 1.0) ⇒ Color

Returns a new instance of Color.



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/less/engine/nodes/literal.rb', line 18

def initialize color = nil, opacity = 1.0
  @color = if color.is_a? Array
    rgba color
  elsif color.is_a? ::String
    color.delete! unit
    (color * ( color.length < 6 ? 6 / color.length : 1 )).to_i 16
  else
    color
  end
  super @color.to_i
end

Instance Attribute Details

#colorObject (readonly)

Returns the value of attribute color.



16
17
18
# File 'lib/less/engine/nodes/literal.rb', line 16

def color
  @color
end

Instance Method Details

#inspectObject



46
# File 'lib/less/engine/nodes/literal.rb', line 46

def inspect; to_s end

#to_cssObject



34
35
36
# File 'lib/less/engine/nodes/literal.rb', line 34

def to_css
  unit + (self <= 0 ? '0' * 6 : self.to_i.to_s(16))
end

#to_rubyObject



38
39
40
# File 'lib/less/engine/nodes/literal.rb', line 38

def to_ruby
  color
end

#to_sObject



42
43
44
# File 'lib/less/engine/nodes/literal.rb', line 42

def to_s
  "#{unit}#{super}"
end

#unitObject



30
31
32
# File 'lib/less/engine/nodes/literal.rb', line 30

def unit
  '#'
end