Class: PryTheme::HEX Private
- Inherits:
-
Object
- Object
- PryTheme::HEX
- Defined in:
- lib/pry-theme/hex.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Conversion to TERM relies on RGB#to_term, as a HEX instance converts itself to RGB first, and only then to TERM.
Represents a HEX colour. It’s possible to convert a HEX instance into TERM or RGB colours. However, this conversion is half-duplex (see RGB). This class validates its input (you won’t see malformed or nonexistent HEX colours).
Constant Summary collapse
- BYTE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Represents a single HEX “digit”.
/[A-F\d]{2}/i
- PATTERN =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
A hex String must be prefixed with an octothorp. Use any letter case.
/\A#(#{ BYTE }){3}\z/i
Instance Method Summary collapse
-
#initialize(value) ⇒ HEX
constructor
private
A new instance of HEX.
- #inspect ⇒ String private
-
#to_rgb ⇒ RGB
private
Converts ‘self` into RGB.
- #to_s ⇒ String private
-
#to_term(color_model = 256) ⇒ RGB
private
Converts ‘self` into TERM.
Constructor Details
#initialize(value) ⇒ HEX
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of HEX.
28 29 30 31 |
# File 'lib/pry-theme/hex.rb', line 28 def initialize(value) validate_value(value) @value = value end |
Instance Method Details
#inspect ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
34 35 36 |
# File 'lib/pry-theme/hex.rb', line 34 def inspect "(HEX: #{ @value })" end |
#to_rgb ⇒ RGB
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts ‘self` into RGB.
47 48 49 |
# File 'lib/pry-theme/hex.rb', line 47 def to_rgb RGB.new(@value[1..-1].scan(BYTE).map! { |b| b.to_i(16) }) end |
#to_s ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
41 42 43 |
# File 'lib/pry-theme/hex.rb', line 41 def to_s @value end |
#to_term(color_model = 256) ⇒ RGB
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts ‘self` into TERM.
53 54 55 |
# File 'lib/pry-theme/hex.rb', line 53 def to_term(color_model = 256) to_rgb.to_term(color_model) end |