Class: TNS::Color::Hex

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

Overview

Hex color representation

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#==, #state

Constructor Details

#initialize(rgb) ⇒ Hex

Returns a new instance of Hex.



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

def initialize(rgb)
  @red, @green, @blue = [rgb.red, rgb.green, rgb.blue].map { |color| normalize(color) }

  super()
end

Instance Attribute Details

#blueObject (readonly)

Returns the value of attribute blue.



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

def blue
  @blue
end

#greenObject (readonly)

Returns the value of attribute green.



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

def green
  @green
end

#redObject (readonly)

Returns the value of attribute red.



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

def red
  @red
end

Instance Method Details

#to_cssObject



15
16
17
# File 'lib/tns/color/hex.rb', line 15

def to_css
  "##{self}"
end

#to_sObject



19
20
21
# File 'lib/tns/color/hex.rb', line 19

def to_s
  "#{red}#{green}#{blue}"
end