Class: ColorGradient

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/color_gradient.rb,
lib/color_gradient/version.rb

Constant Summary collapse

VERSION =
"0.2.1"

Instance Method Summary collapse

Constructor Details

#initialize(start, stop, resolution) ⇒ ColorGradient

Returns a new instance of ColorGradient.

Raises:

  • (ArgumentError)


10
11
12
13
14
15
16
17
18
19
# File 'lib/color_gradient.rb', line 10

def initialize(start, stop, resolution)
  raise ArgumentError, 'start Argument is not Color gem object' unless start.is_a? Color
  raise ArgumentError, 'stop Argument is not Color gem object' unless stop.is_a? Color
  raise ArgumentError, 'resolution Argument is not integer' unless resolution.is_a? Integer

  @start      = start.freeze
  @stop       = stop.freeze
  @resolution = Float(resolution).freeze
  @colours    = generate_colours.freeze
end

Instance Method Details

#gradient(step) ⇒ Object



21
22
23
# File 'lib/color_gradient.rb', line 21

def gradient(step)
  colours[step]
end