Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/color/string.rb
Overview
Monkey patch String class with color conversion utility methods
Instance Method Summary collapse
-
#to_color(format = :hex) ⇒ Object
Convert a String to color.
Instance Method Details
#to_color(format = :hex) ⇒ Object
Convert a String to color
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/color/string.rb', line 11 def to_color(format = :hex) format = format.to_sym if format == :hex text = self.sub(/0x/, '') return Color::RGB.by_hex(text) end if format == :html return Color::RGB.from_html(self) end if format == :name return Color::Maker.by_name(self) end raise "Unknown format: #{format}" end |