Class: PryTheme::Color::Declaration Private
- Inherits:
-
Object
- Object
- PryTheme::Color::Declaration
- Defined in:
- lib/pry-theme/declaration.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.
Class Method Summary collapse
- .translate(decl, color_model) ⇒ Object (also: t) private
Instance Method Summary collapse
-
#initialize(color_decl, color_model) ⇒ Declaration
constructor
private
A new instance of Declaration.
- #parse ⇒ Object private
- #to_color ⇒ Object private
Constructor Details
#initialize(color_decl, color_model) ⇒ Declaration
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 Declaration.
17 18 19 20 21 22 23 24 25 |
# File 'lib/pry-theme/declaration.rb', line 17 def initialize(color_decl, color_model) validate_effects(color_decl, color_model) @color_decl = color_decl @color_model = color_model @color_class = PryTheme.const_get(:"Color#{ color_model }") @effects = {} @parsed = false end |
Class Method Details
.translate(decl, color_model) ⇒ Object Also known as: t
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.
9 10 11 12 13 |
# File 'lib/pry-theme/declaration.rb', line 9 def translate(decl, color_model) decl = Declaration.new(decl, color_model) decl.parse decl.to_color end |
Instance Method Details
#parse ⇒ Object
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.
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/pry-theme/declaration.rb', line 27 def parse if @parsed return else case @color_decl.size when 3 then build_from_two_layers when 2 then build_from_two_args when 1 then build_from_arg end @parsed = true end end |
#to_color ⇒ Object
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.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/pry-theme/declaration.rb', line 40 def to_color [:readable, :hex, :rgb, :term].each do |type| begin return @color_class.new({ :from => type, :foreground => @fg, :background => @bg }.merge!(@effects)) rescue ArgumentError, TypeError next end end raise PryTheme::ThemeError, %|malformed color declaration (#{ [@fg, @bg].compact.join(', ') })| end |