Class: StyleTrain::Color
- Inherits:
-
Object
- Object
- StyleTrain::Color
- Defined in:
- lib/style_train/color.rb
Instance Attribute Summary collapse
-
#background_set ⇒ Object
Returns the value of attribute background_set.
-
#delegate ⇒ Object
Returns the value of attribute delegate.
Class Method Summary collapse
Instance Method Summary collapse
- #==(color) ⇒ Object
- #=~(color) ⇒ Object
- #alpha=(value) ⇒ Object
-
#background ⇒ Object
rendering.
- #background=(opts) ⇒ Object
- #color_types ⇒ Object
-
#initialize(color, opts = {}) ⇒ Color
constructor
Constructor.
- #inspect ⇒ Object
- #render(render_style = nil) ⇒ Object
- #step(end_color, steps = 10) ⇒ Object
- #to(key) ⇒ Object
- #to_s(render_style = nil) ⇒ Object
Constructor Details
#initialize(color, opts = {}) ⇒ Color
Constructor
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/style_train/color.rb', line 7 def initialize( color, opts={} ) opts = Gnash.new(opts).merge(:color => color) background_opts = opts.delete(:background) self.background = background_opts if background_opts if color.is_a?(Color) self.delegate = color.delegate.dup self.alpha = opts[:alpha] if opts[:alpha] self.background = color.background if color.background_set else color_types.each do |klass| if instance = klass.make(opts) self.delegate = instance break end end end end |
Instance Attribute Details
#background_set ⇒ Object
Returns the value of attribute background_set.
4 5 6 |
# File 'lib/style_train/color.rb', line 4 def background_set @background_set end |
#delegate ⇒ Object
Returns the value of attribute delegate.
4 5 6 |
# File 'lib/style_train/color.rb', line 4 def delegate @delegate end |
Class Method Details
.color_types ⇒ Object
25 26 27 |
# File 'lib/style_train/color.rb', line 25 def self.color_types @color_type ||= ColorType.color_types end |
Instance Method Details
#==(color) ⇒ Object
58 59 60 |
# File 'lib/style_train/color.rb', line 58 def ==( color ) color.is_a?( Color ) && self =~ color && self.background == color.background end |
#=~(color) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/style_train/color.rb', line 50 def =~( color ) if color.is_a?(Color) self.delegate =~ color.delegate elsif color.is_a?( ColorType ) self.delegate =~ color end end |
#alpha=(value) ⇒ Object
42 43 44 |
# File 'lib/style_train/color.rb', line 42 def alpha=( value ) self.delegate.alpha = value end |
#background ⇒ Object
rendering
63 64 65 |
# File 'lib/style_train/color.rb', line 63 def background @background ||= Color.new(:white).to(:hex) end |
#background=(opts) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/style_train/color.rb', line 67 def background=( opts ) color = opts.is_a?(Hash) && (opts[:color] || opts['color']) @background = if color opts.delete(:alpha) Color.new(color, opts) elsif opts.is_a? Color color = opts.dup # so that the original color's alpha isn't affected color.alpha = 1.0 color else Color.new(opts) end raise ArgumentError, "Background with color: #{color} and options: #{opts} not found" unless @background raise ArgumentError, "Background color #{@background.inspect} has no delegate color" unless @background.delegate self.background_set = true @background end |
#color_types ⇒ Object
29 30 31 |
# File 'lib/style_train/color.rb', line 29 def color_types self.class.color_types end |
#inspect ⇒ Object
107 108 109 |
# File 'lib/style_train/color.rb', line 107 def inspect "<Color @delegate=#{self.delegate.to_s} @background=#{self.background}>" end |
#render(render_style = nil) ⇒ Object
99 100 101 102 103 104 105 |
# File 'lib/style_train/color.rb', line 99 def render(render_style=nil) if render_style && render_style.to_sym == :ie self.background.to(:hex).layer(self.delegate).render else self.delegate.render end end |
#step(end_color, steps = 10) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/style_train/color.rb', line 87 def step(end_color, steps=10) start_color = self.delegate end_color = end_color.delegate array = [start_color] (2..(steps-1)).each do |number| ratio = 1 - (steps-number)/steps.to_f array << start_color.mix(end_color, ratio) end array << end_color array end |
#to(key) ⇒ Object
46 47 48 |
# File 'lib/style_train/color.rb', line 46 def to(key) self.delegate.to(key) end |
#to_s(render_style = nil) ⇒ Object
111 112 113 |
# File 'lib/style_train/color.rb', line 111 def to_s(render_style=nil) render(render_style) end |