Class: Coloration::Style

Inherits:
Object show all
Defined in:
lib/coloration/style.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(obj = nil, bg = nil) ⇒ Style

Returns a new instance of Style.



6
7
8
9
10
11
12
13
14
15
# File 'lib/coloration/style.rb', line 6

def initialize(obj=nil, bg=nil)
  if obj
    case obj
    when String
      initialize_from_hash({ :foreground => obj }, bg)
    when Hash
      initialize_from_hash(obj, bg)
    end
  end
end

Instance Attribute Details

#backgroundObject

Returns the value of attribute background.



4
5
6
# File 'lib/coloration/style.rb', line 4

def background
  @background
end

#boldObject

Returns the value of attribute bold.



4
5
6
# File 'lib/coloration/style.rb', line 4

def bold
  @bold
end

#commentObject

Returns the value of attribute comment.



4
5
6
# File 'lib/coloration/style.rb', line 4

def comment
  @comment
end

#foregroundObject

Returns the value of attribute foreground.



4
5
6
# File 'lib/coloration/style.rb', line 4

def foreground
  @foreground
end

#inverseObject

Returns the value of attribute inverse.



4
5
6
# File 'lib/coloration/style.rb', line 4

def inverse
  @inverse
end

#italicObject

Returns the value of attribute italic.



4
5
6
# File 'lib/coloration/style.rb', line 4

def italic
  @italic
end

#strikeObject

Returns the value of attribute strike.



4
5
6
# File 'lib/coloration/style.rb', line 4

def strike
  @strike
end

#underlineObject

Returns the value of attribute underline.



4
5
6
# File 'lib/coloration/style.rb', line 4

def underline
  @underline
end

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/coloration/style.rb', line 32

def blank?
  foreground.nil? && background.nil?
end

#initialize_from_hash(h, bg = nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/coloration/style.rb', line 17

def initialize_from_hash(h, bg=nil)
  h.each do |key, value|
    if key == :fg
      key = :foreground
    end
    if key == :bg
      key = :background
    end
    if ["foreground", "background"].include?(key.to_s) && value.is_a?(String)
      value = Color::RGBA.from_html(value, bg)
    end
    send("#{key}=", value)
  end
end