Class: TNS::Color::HSL

Inherits:
Object
  • Object
show all
Defined in:
lib/tns/color/hsl.rb

Overview

HSL is our base representation for color objects.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rgb) ⇒ HSL

Returns a new instance of HSL.



9
10
11
12
# File 'lib/tns/color/hsl.rb', line 9

def initialize(rgb)
  @hue, @saturation, @lightness = from_rgb(rgb)
  super()
end

Instance Attribute Details

#hueObject (readonly)

Returns the value of attribute hue.



7
8
9
# File 'lib/tns/color/hsl.rb', line 7

def hue
  @hue
end

#lightnessObject (readonly)

Returns the value of attribute lightness.



7
8
9
# File 'lib/tns/color/hsl.rb', line 7

def lightness
  @lightness
end

#saturationObject (readonly)

Returns the value of attribute saturation.



7
8
9
# File 'lib/tns/color/hsl.rb', line 7

def saturation
  @saturation
end

Instance Method Details

#to_cssObject



14
15
16
# File 'lib/tns/color/hsl.rb', line 14

def to_css
  "hsl(#{self})"
end

#to_sObject



18
19
20
# File 'lib/tns/color/hsl.rb', line 18

def to_s
  format("%<hue>d %<saturation>d %<lightness>d", hue: @hue, saturation: @saturation, lightness: @lightness)
end