Class: Vic::Color
- Inherits:
-
Object
- Object
- Vic::Color
- Defined in:
- lib/vic/color.rb
Defined Under Namespace
Classes: ColorError
Instance Attribute Summary collapse
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
-
#cterm? ⇒ TrueClass, FalseClass
Returns true if the color value is cterm compatible color and false if it’s not.
-
#gui? ⇒ TrueClass, FalseClass
Returns true if the color value is a gui compatible color and false if it’s not.
-
#hexadecimal? ⇒ TrueClass, FalseClass
Returns true if the color value is a hexadecimal color and false if it’s not.
-
#initialize(value) ⇒ Color
constructor
A new instance of Color.
-
#none? ⇒ TrueClass, FalseClass
Returns true if the color value is either empty or set to “NONE”.
-
#to_cterm ⇒ Fixnum
Convert the color value to a cterm compatible color.
-
#to_gui ⇒ Symbol, String
Convert the color value to a hexadecimal color.
Constructor Details
#initialize(value) ⇒ Color
Returns a new instance of Color.
5 6 7 |
# File 'lib/vic/color.rb', line 5 def initialize(value) @value = value end |
Instance Attribute Details
#value ⇒ Object
Returns the value of attribute value.
3 4 5 |
# File 'lib/vic/color.rb', line 3 def value @value end |
Instance Method Details
#cterm? ⇒ TrueClass, FalseClass
Returns true if the color value is cterm compatible color and false if it’s not
46 47 48 |
# File 'lib/vic/color.rb', line 46 def cterm? @value.kind_of?(Fixnum) and @value.between?(0, 255) end |
#gui? ⇒ TrueClass, FalseClass
Returns true if the color value is a gui compatible color and false if it’s not
57 58 59 |
# File 'lib/vic/color.rb', line 57 def gui? hexadecimal? end |
#hexadecimal? ⇒ TrueClass, FalseClass
Returns true if the color value is a hexadecimal color and false if it’s not
67 68 69 70 |
# File 'lib/vic/color.rb', line 67 def hexadecimal? # Both standard and shorthand (CSS) style hexadecimal color value. not cterm? and /\A#?(?:[0-9a-f]{3}|[0-9a-f]{6})\z/io.match(@value.to_s) end |
#none? ⇒ TrueClass, FalseClass
Returns true if the color value is either empty or set to “NONE”
78 79 80 |
# File 'lib/vic/color.rb', line 78 def none? @value.to_s.empty? or /\Anone\z/io.match(@value.to_s) end |
#to_cterm ⇒ Fixnum
Convert the color value to a cterm compatible color
31 32 33 34 35 36 37 |
# File 'lib/vic/color.rb', line 31 def to_cterm return @value if cterm? return Convert.hex_to_xterm(to_standard_hex) if hexadecimal? return :NONE if none? raise ColorError.new "can't convert \"#{ @value }\" to cterm" end |
#to_gui ⇒ Symbol, String
Convert the color value to a hexadecimal color
17 18 19 20 21 22 23 |
# File 'lib/vic/color.rb', line 17 def to_gui return to_standard_hex if hexadecimal? return Convert.xterm_to_hex(@value) if cterm? return :NONE if none? raise ColorError.new "can't convert \"#{ @value }\" to gui" end |