gradient 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 89ea4e065588742732ec1adee2b95bbee71e80e6
4
- data.tar.gz: 64aff1fdd843d4aae818c65b44ccfe88cc0d4f06
3
+ metadata.gz: 2b086f81d5d8bc9667fd9ecf8272f154f882402d
4
+ data.tar.gz: 2ddcd6b8f68940d5dca3f7b6b18809cdc0a73416
5
5
  SHA512:
6
- metadata.gz: 529165c3d1ae1890d664b593cf2a830ef05c01465e7f6a3831aaa35400ef34eb1855047d2cb719e541c93c6f1e820f41d7514d12ffae9c46ce1962a2b2b68891
7
- data.tar.gz: 652bf1bf09cb2d368370dda36be71286e4400222419d74579823da7b579539c1469bbed2580d65576325e86d4d00d8914b86dcb32bf6a953ac9b42e060e199e6
6
+ metadata.gz: 7487c077ae4393109c689ea7ffef938108059d6965e8e04e47747fa8be7d97444f444f3364571de9ad813f604169371b542810c71ef669889cd238bec15675e5
7
+ data.tar.gz: 46c68629d2e91dfa0432a230886a28c68e60450ab2eef160d8ff2434b91fef2cf68b04c16c2dcf31ae43d92f0c82d6bb4282549e91c880cf5cbae63a9a3b5449
@@ -3,6 +3,12 @@ module Gradient
3
3
 
4
4
  attr_reader :points, :locations
5
5
 
6
+ class << self
7
+ def deserialize(points=[])
8
+ new(points.map { |point| Gradient::Point.deserialize(*point) })
9
+ end
10
+ end
11
+
6
12
  def initialize(*points)
7
13
  @points = points.flatten.sort
8
14
  @locations = @points.map { |point| point.location }
@@ -17,5 +23,13 @@ module Gradient
17
23
  @css_printer.css(**args)
18
24
  end
19
25
 
26
+ def serialize
27
+ @points.map(&:serialize)
28
+ end
29
+
30
+ def as_json(json={})
31
+ serialize
32
+ end
33
+
20
34
  end
21
35
  end
@@ -3,6 +3,20 @@ module Gradient
3
3
 
4
4
  attr_reader :location, :color, :opacity
5
5
 
6
+ class << self
7
+ def deserialize(location, color_type, color_values, opacity)
8
+ self.new(location, color_from(color_type, color_values), opacity)
9
+ end
10
+
11
+ private def color_from(color_type, color_values)
12
+ case color_type
13
+ when "rgb" then Color::RGB.new(*color_values)
14
+ else
15
+ raise NotImplementedError.new("#{string} is not a valid color type")
16
+ end
17
+ end
18
+ end
19
+
6
20
  def initialize(location, color, opacity)
7
21
  @location, @color, @opacity = location, color, opacity
8
22
  end
@@ -15,5 +29,20 @@ module Gradient
15
29
  self.location <=> other.location
16
30
  end
17
31
 
32
+ def serialize
33
+ [location, "rgb", [color.red.round, color.green.round, color.blue.round], opacity]
34
+ end
35
+
36
+ def as_json(json={})
37
+ serialize
38
+ end
39
+
40
+ def ==(other)
41
+ unless other.kind_of?(Gradient::Point)
42
+ raise ArgumentError.new("cannot compare Point with #{ other.class } using `=='")
43
+ end
44
+ location == other.location && color == other.color && opacity == other.opacity
45
+ end
46
+
18
47
  end
19
48
  end
@@ -1,3 +1,3 @@
1
1
  module Gradient
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gradient
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philip Vieira