Class: Color::Scheme
Overview
classes or methods, or factory?
Direct Known Subclasses
Analogous, Complementary, DoubleComplementary, Hues, Monochromatic, SplitComplementary, Triadic
Instance Attribute Summary collapse
-
#hues ⇒ Object
readonly
Returns the value of attribute hues.
Class Method Summary collapse
-
.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.
Instance Method Summary collapse
- #add_hue(val) ⇒ Object
-
#initialize ⇒ Scheme
constructor
A new instance of Scheme.
Constructor Details
#initialize ⇒ Scheme
Returns a new instance of Scheme.
38 39 40 |
# File 'lib/color/scheme.rb', line 38 def initialize @hues = Array.new end |
Instance Attribute Details
#hues ⇒ Object (readonly)
Returns the value of attribute hues.
36 37 38 |
# File 'lib/color/scheme.rb', line 36 def hues @hues end |
Class Method Details
.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 |
Instance Method Details
#add_hue(val) ⇒ Object
42 43 44 45 46 |
# File 'lib/color/scheme.rb', line 42 def add_hue(val) hue = self.class.create_hue(val) @hues << hue hue end |