Class: RGhost::Color
- Includes:
- RubyToPs
- Defined in:
- lib/rghost/color.rb
Overview
Creates color for postscript components
Constant Summary
Constants included from RubyToPs
Class Method Summary collapse
-
.create(color = "FFAA99") ⇒ Object
The method create is a color factory depends when parameter is used.
Methods included from RubyToPs
#array_to_stack, #hash_to_array, #pack_string, #ps_escape, #string_eval, #to_array, #to_bool, #to_string, #to_string_array
Methods inherited from PsObject
#<<, #call, #graphic_scope, #initialize, #ps, #raw, #set, #to_s
Constructor Details
This class inherits a constructor from RGhost::PsObject
Class Method Details
.create(color = "FFAA99") ⇒ Object
The method create is a color factory depends when parameter is used. The parameter variate between 0 and 1, if value greatet that 1 will be divided by 100.0 .
Examples
Creating RGB color
String HTML color converter Color.create ‘#FFAA33’ As Symbol will be find in RGhost::Constants::Colors::RGB Color.create :red
As Array with 3 elements Color.create [0.5, 0.3, 0.5] Hash with 3 pair of key/value. Valids keys :red, :green and :blue Color.create :red => 0.5, :green => 0.3, :blue => 0.5 Hash with 3 pair of key/value. Valids keys :r, :g and :b Color.create :r => 0.5, :g => 0.3, :b => 0.5
Creating CMYK color
Hash with 4 pair of key/value. Valids keys :cyan, :magenta, :yellow and :black
Color.create :cyan=> 1 ,:magenta => 0.3, :yellow => 0, :black => 0
Hash with 4 pair of key/value. Valids keys :c, :m, :y and :b
Color.create :c=> 1 ,:m => 0.3, :y => 0, :b => 0
Creating CMYK Spot color
Hash with 5 pair of key/value. Valids keys :cyan, :magenta, :yellow, :black, and :name
Color.create :cyan=> 0, :magenta => 100, :yellow => 63, :black => 12, :name => 'Pantone 200 C'
Creating Gray color
A single Numeric Color.create 0.5 50 percent of black will be divided by 100.0 Color.create 50
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rghost/color.rb', line 35 def self.create(color="FFAA99") return case color when String then RGhost::RGB.new(color) when Symbol then c=RGhost::Constants::Colors::RGB[color] raise ArgumentError.new("#{color}##{color.class}") unless c self.create c when Array, Hash then if color.size == 3 RGhost::RGB.new(color) elsif color.size == 4 RGhost::CMYK.new(color) elsif color.size == 5 RGhost::CMYKSpot.new(color) else raise ArgumentError.new("#{color}##{color.class}") end when Numeric then RGhost::Gray.new(color) else raise ArgumentError.new("#{color}##{color.class}") end end |