Class: Gradient::Map

Inherits:
Object
  • Object
show all
Defined in:
lib/gradient/map.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(color_points = [], opacity_points = []) ⇒ Map

Returns a new instance of Map.



6
7
8
9
10
11
12
13
14
# File 'lib/gradient/map.rb', line 6

def initialize(color_points=[], opacity_points=[])
  color_points << Gradient::ColorPoint.new(0, Color::RGB.new(255, 255, 255)) if color_points.empty?
  opacity_points << Gradient::OpacityPoint.new(0, 1) if opacity_points.empty?
  @color_points = sort_points(Array(color_points))
  @opacity_points = sort_points(Array(opacity_points))
  @all_points = sort_points(@color_points + @opacity_points)
  @locations = @all_points.map { |point| point.location }.uniq
  @points ||= merge_color_and_opacity_points
end

Instance Attribute Details

#color_pointsObject (readonly)

Returns the value of attribute color_points.



4
5
6
# File 'lib/gradient/map.rb', line 4

def color_points
  @color_points
end

#opacity_pointsObject (readonly)

Returns the value of attribute opacity_points.



4
5
6
# File 'lib/gradient/map.rb', line 4

def opacity_points
  @opacity_points
end

#pointsObject (readonly)

Returns the value of attribute points.



4
5
6
# File 'lib/gradient/map.rb', line 4

def points
  @points
end

Instance Method Details

#inspectObject



16
17
18
# File 'lib/gradient/map.rb', line 16

def inspect
  "#<Gradient Map #{points.map(&:inspect).join(" ")}>"
end

#to_css(**args) ⇒ Object



20
21
22
23
# File 'lib/gradient/map.rb', line 20

def to_css(**args)
  @css_printer ||= Gradient::CSSPrinter.new(self)
  @css_printer.css(**args)
end