Class: Gradient::Point
- Inherits:
-
Object
- Object
- Gradient::Point
- Defined in:
- lib/gradient/point.rb
Instance Attribute Summary collapse
-
#color ⇒ Object
readonly
Returns the value of attribute color.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#opacity ⇒ Object
readonly
Returns the value of attribute opacity.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
- #as_json(json = {}) ⇒ Object
-
#initialize(location, color, opacity) ⇒ Point
constructor
A new instance of Point.
- #inspect ⇒ Object
- #serialize ⇒ Object
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
#color ⇒ Object (readonly)
Returns the value of attribute color.
4 5 6 |
# File 'lib/gradient/point.rb', line 4 def color @color end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
4 5 6 |
# File 'lib/gradient/point.rb', line 4 def location @location end |
#opacity ⇒ Object (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 |
#inspect ⇒ Object
24 25 26 |
# File 'lib/gradient/point.rb', line 24 def inspect "#<Point #{location * 100} ##{color.hex}#{"%02x" % (opacity * 255).round}>" end |
#serialize ⇒ Object
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 |