Class: Gradient::Point

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(location, color, opacity) ⇒ Point

Returns a new instance of Point.



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

def initialize(location, color, opacity)
  @location, @color, @opacity = location, color, opacity
end

Instance Attribute Details

#colorObject (readonly)

Returns the value of attribute color.



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

def color
  @color
end

#locationObject (readonly)

Returns the value of attribute location.



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

def location
  @location
end

#opacityObject (readonly)

Returns the value of attribute opacity.



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

def opacity
  @opacity
end

Class Method Details

.deserialize(location, color_type, color_values, opacity) ⇒ Object



7
8
9
# File 'lib/gradient/point.rb', line 7

def deserialize(location, color_type, color_values, opacity)
  self.new(location, color_from(color_type, color_values), opacity)
end

Instance Method Details

#<=>(other) ⇒ Object



28
29
30
# File 'lib/gradient/point.rb', line 28

def <=>(other)
  self.location <=> other.location
end

#==(other) ⇒ Object



40
41
42
43
44
45
# File 'lib/gradient/point.rb', line 40

def ==(other)
  unless other.kind_of?(Gradient::Point)
    raise ArgumentError.new("cannot compare Point with #{ other.class } using `=='")
  end
  location == other.location && color == other.color && opacity == other.opacity
end

#as_json(json = {}) ⇒ Object



36
37
38
# File 'lib/gradient/point.rb', line 36

def as_json(json={})
  serialize
end

#inspectObject



24
25
26
# File 'lib/gradient/point.rb', line 24

def inspect
  "#<Point #{location * 100} ##{color.hex}#{"%02x" % (opacity * 255).round}>"
end

#serializeObject



32
33
34
# File 'lib/gradient/point.rb', line 32

def serialize
  [location, "rgb", [color.red.round, color.green.round, color.blue.round], opacity]
end