Class: Shi::Args::Value::Color
- Inherits:
-
Object
- Object
- Shi::Args::Value::Color
- Defined in:
- lib/shi/args/values.rb
Instance Attribute Summary collapse
- #alpha ⇒ Integer readonly
- #blue ⇒ Integer readonly
- #green ⇒ Integer readonly
- #red ⇒ Integer readonly
- #value ⇒ String readonly
Instance Method Summary collapse
-
#initialize(source) ⇒ Color
constructor
A new instance of Color.
- #to_s ⇒ String
Constructor Details
#initialize(source) ⇒ Color
Returns a new instance of Color.
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
#alpha ⇒ Integer (readonly)
23 24 25 |
# File 'lib/shi/args/values.rb', line 23 def alpha @alpha end |
#blue ⇒ Integer (readonly)
20 21 22 |
# File 'lib/shi/args/values.rb', line 20 def blue @blue end |
#green ⇒ Integer (readonly)
17 18 19 |
# File 'lib/shi/args/values.rb', line 17 def green @green end |
#red ⇒ Integer (readonly)
14 15 16 |
# File 'lib/shi/args/values.rb', line 14 def red @red end |
#value ⇒ String (readonly)
11 12 13 |
# File 'lib/shi/args/values.rb', line 11 def value @value end |
Instance Method Details
#to_s ⇒ String
56 57 58 |
# File 'lib/shi/args/values.rb', line 56 def to_s @value end |