Class: Less::Node::Color
- Includes:
- Literal
- Defined in:
- lib/less/engine/nodes/literal.rb
Overview
rgb(255, 0, 0) #f0f0f0
Instance Attribute Summary collapse
-
#color ⇒ Object
readonly
Returns the value of attribute color.
Attributes included from Entity
Instance Method Summary collapse
-
#initialize(color = nil, opacity = 1.0) ⇒ Color
constructor
A new instance of Color.
- #inspect ⇒ Object
- #to_css ⇒ Object
- #to_ruby ⇒ Object
- #to_s ⇒ Object
- #unit ⇒ Object
Methods included from Entity
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
#color ⇒ Object (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
#inspect ⇒ Object
46 |
# File 'lib/less/engine/nodes/literal.rb', line 46 def inspect; to_s end |
#to_css ⇒ Object
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_ruby ⇒ Object
38 39 40 |
# File 'lib/less/engine/nodes/literal.rb', line 38 def to_ruby color end |
#to_s ⇒ Object
42 43 44 |
# File 'lib/less/engine/nodes/literal.rb', line 42 def to_s "#{unit}#{super}" end |
#unit ⇒ Object
30 31 32 |
# File 'lib/less/engine/nodes/literal.rb', line 30 def unit '#' end |