Class: PdfUtils::Color
- Inherits:
-
Object
- Object
- PdfUtils::Color
- Defined in:
- lib/pdf_utils/color.rb
Instance Method Summary collapse
-
#initialize(*args) ⇒ Color
constructor
A new instance of Color.
- #to_hex ⇒ Object
- #to_pdf ⇒ Object
- #to_rgb ⇒ Object
Constructor Details
#initialize(*args) ⇒ Color
Returns a new instance of Color.
3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/pdf_utils/color.rb', line 3 def initialize(*args) if args.first.is_a?(String) @r, @g, @b = args.first.scan(/../).map{ |rgb| rgb.to_i(16) } elsif args.size == 3 if args.any? {|arg| arg.kind_of?(Float) } @r, @g, @b = args.map {|v| (v * 255).to_i } else @r, @g, @b = args end end end |
Instance Method Details
#to_hex ⇒ Object
19 20 21 |
# File 'lib/pdf_utils/color.rb', line 19 def to_hex to_rgb.inject(''){ |hex, v| hex << "%02x" % v } end |
#to_pdf ⇒ Object
15 16 17 |
# File 'lib/pdf_utils/color.rb', line 15 def to_pdf to_rgb.map{ |v| v / 255.0 } end |
#to_rgb ⇒ Object
23 24 25 |
# File 'lib/pdf_utils/color.rb', line 23 def to_rgb [@r, @g, @b] end |