Class: PryTheme::Color::Declaration Private

Inherits:
Object
  • Object
show all
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.

Since:

  • 0.2.0

Class Method Summary collapse

Instance Method Summary collapse

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.

Since:

  • 0.2.0



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.

Since:

  • 0.2.0



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

#parseObject

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.

Since:

  • 0.2.0



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_colorObject

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.

Raises:

Since:

  • 0.2.0



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