Class: TNS::Color::Variant

Inherits:
Base
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/tns/color/variant.rb

Overview

A variant of a color, which could be either a tint or a shade.

Direct Known Subclasses

Shade, Tint

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#==, #state, #to_css, #to_s

Constructor Details

#initialize(color, step) ⇒ Variant

Returns a new instance of Variant.



15
16
17
18
19
# File 'lib/tns/color/variant.rb', line 15

def initialize(color, step)
  @color = color
  @step = step
  super()
end

Instance Attribute Details

#colorObject (readonly)

Returns the value of attribute color.



11
12
13
# File 'lib/tns/color/variant.rb', line 11

def color
  @color
end

#stepObject (readonly)

Returns the value of attribute step.



11
12
13
# File 'lib/tns/color/variant.rb', line 11

def step
  @step
end

Instance Method Details

#indexObject

Return the step relative to base color. Step 0 has in index of 5, tints and shades have indices relative to that.



35
36
37
# File 'lib/tns/color/variant.rb', line 35

def index
  raise NotImplementedError("Implement this for shades or tints")
end

#to_hexObject

Change the internal color representation to Hex



22
23
24
25
# File 'lib/tns/color/variant.rb', line 22

def to_hex
  @color = @color.to_hex
  self
end

#to_hslObject

Change the internal color representation to HSL



28
29
30
31
# File 'lib/tns/color/variant.rb', line 28

def to_hsl
  @color = @color.to_hsl
  self
end