Class: Shi::Args::Value::Color

Inherits:
Object
  • Object
show all
Defined in:
lib/shi/args/values.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ Color

Returns a new instance of Color.

Parameters:

  • source (String)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/shi/args/values.rb', line 26

def initialize source
  @value = source.strip
  plain = @value.slice(1..-1)
  case plain.length
  when 3
    @red = (plain.slice(0) * 2).to_i(16)
    @green = (plain.slice(1) * 2).to_i(16)
    @blue = (plain.slice(2) * 2).to_i(16)
    @alpha = nil
  when 4
    @red = (plain.slice(0) * 2).to_i(16)
    @green = (plain.slice(1) * 2).to_i(16)
    @blue = (plain.slice(2) * 2).to_i(16)
    @alpha = (plain.slice(3) * 2).to_i(16)
  when 6
    @red = plain.slice(0..1).to_i(16)
    @green = plain.slice(2..3).to_i(16)
    @blue = plain.slice(4..5).to_i(16)
    @alpha = nil
  when 8
    @red = plain.slice(0..1).to_i(16)
    @green = plain.slice(2..3).to_i(16)
    @blue = plain.slice(4..5).to_i(16)
    @alpha = plain.slice(6..7).to_i(16)
  else
    raise ArgumentError, "Invalid color: #{source}"
  end
end

Instance Attribute Details

#alphaInteger (readonly)

Returns:

  • (Integer)


23
24
25
# File 'lib/shi/args/values.rb', line 23

def alpha
  @alpha
end

#blueInteger (readonly)

Returns:

  • (Integer)


20
21
22
# File 'lib/shi/args/values.rb', line 20

def blue
  @blue
end

#greenInteger (readonly)

Returns:

  • (Integer)


17
18
19
# File 'lib/shi/args/values.rb', line 17

def green
  @green
end

#redInteger (readonly)

Returns:

  • (Integer)


14
15
16
# File 'lib/shi/args/values.rb', line 14

def red
  @red
end

#valueString (readonly)

Returns:

  • (String)


11
12
13
# File 'lib/shi/args/values.rb', line 11

def value
  @value
end

Instance Method Details

#to_sString

Returns:

  • (String)


56
57
58
# File 'lib/shi/args/values.rb', line 56

def to_s
  @value
end