Sha256: 6545c9c973346911e1624c1f408789420a3d2a492fdaf650e3073b80aac91b45

Contents?: true

Size: 854 Bytes

Versions: 1

Compression:

Stored size: 854 Bytes

Contents

module Coloration

  class Style

    attr_accessor :foreground, :background, :bold, :italic, :underline, :strike, :inverse, :comment

    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

    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

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

  end # Style

end # Coloration

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
coloration-0.4.0 lib/coloration/style.rb