Method: Color::Scheme.create_hue
- Defined in:
- lib/color/scheme.rb
.create_hue(value) ⇒ Object
creates a hue from the value, processing it as a hue (0-360) or as RRGGBB, or generating a random one, if nil or an empty string.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/color/scheme.rb', line 18 def self.create_hue(value) if value.nil? (rand * 360).round elsif value.kind_of? Numeric value.round % 360 elsif value.kind_of? String if %r{^\d{3}$}.match(value) value.to_i.round % 360 elsif md = Color::RGB::RRGGBB_REGEXP.match(value) Color::RGB.new(value).to_hsb.hue else raise RuntimeError.new("invalid hue value '#{value}") end else raise RuntimeError.new("invalid hue value '#{value}") end end |