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 +4 -4
- data/lib/gradient/map.rb +14 -0
- data/lib/gradient/point.rb +29 -0
- data/lib/gradient/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b086f81d5d8bc9667fd9ecf8272f154f882402d
|
4
|
+
data.tar.gz: 2ddcd6b8f68940d5dca3f7b6b18809cdc0a73416
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7487c077ae4393109c689ea7ffef938108059d6965e8e04e47747fa8be7d97444f444f3364571de9ad813f604169371b542810c71ef669889cd238bec15675e5
|
7
|
+
data.tar.gz: 46c68629d2e91dfa0432a230886a28c68e60450ab2eef160d8ff2434b91fef2cf68b04c16c2dcf31ae43d92f0c82d6bb4282549e91c880cf5cbae63a9a3b5449
|
data/lib/gradient/map.rb
CHANGED
@@ -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
|
data/lib/gradient/point.rb
CHANGED
@@ -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
|
data/lib/gradient/version.rb
CHANGED