gradient 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c90b95d6eda4af13387ef56d48ee13c135ae97dd
4
- data.tar.gz: ce7e64d799a4587190a79d3934f023aa4c8908c5
3
+ metadata.gz: b8a4cda55417c291a922c291959867947aa8b93a
4
+ data.tar.gz: a5a1564b1ae76f25ebb4eed1f804123fa9cf6102
5
5
  SHA512:
6
- metadata.gz: 8169e8ba9be408feb1007d7bbfc0f7627613f3632091df5635b1aa126036813c28c35a26d764c1304315579dbc45bd8c4e579a814b6bcac390498fa7b5642cbc
7
- data.tar.gz: ebc81c832dc63be8435c7fad298e1f1ad41f467c762e25e86ae9be57686681f2dbb01024c8a34c9f1dde880a35b9124080aaee0ae0e058898b98961d04c4cfba
6
+ metadata.gz: edf334904f263f9bfd9274d5f4cec5712c309c5b9a41e0032b982eee016edb76292da173dd2fb6cecedca30dd1ca963669b6c396e34d61d7ce0aa8742424980a
7
+ data.tar.gz: 68cc22eacc507b58b6d40bbc4bfca6919f328e53a0dfa06ced5f378e3dd0a576566e0e7034e6114369b5fbbd9c950ecbff8990d04daac8f586122b7ed3024a57
data/lib/gradient/grd.rb CHANGED
@@ -115,13 +115,13 @@ module Gradient
115
115
 
116
116
  private def convert_to_color(color_data)
117
117
  case format = color_data["palette"]
118
- when "CMYC" then Color::CMYK.from_percent(*color_data.values_at("Cyn", "Mgnt", "Ylw", "Blck").map(&:round))
118
+ when "CMYC" then Color::CMYK.from_percent(*color_data.values_at("Cyn", "Mgnt", "Ylw", "Blck").map(&:round)).to_rgb
119
119
  when "RGBC" then Color::RGB.new(*color_data.values_at("Rd", "Grn", "Bl").map(&:round))
120
120
  when "HSBC"
121
121
  h = color_data.fetch("H")
122
122
  s = color_data.fetch("Strt") / 100.0
123
123
  l = color_data.fetch("Brgh") / 100.0
124
- Color::HSL.from_fraction(h, s, l)
124
+ Color::HSL.from_fraction(h, s, l).to_rgb
125
125
  else
126
126
  raise NotImplementedError.new("The color #{format} is not supported")
127
127
  end
data/lib/gradient/map.rb CHANGED
@@ -10,7 +10,7 @@ module Gradient
10
10
  @opacity_points = sort_points(Array(opacity_points))
11
11
  @all_points = sort_points(@color_points + @opacity_points)
12
12
  @locations = @all_points.map { |point| point.location }.uniq
13
- @points ||= expand_points
13
+ @points ||= merge_color_and_opacity_points
14
14
  end
15
15
 
16
16
  def inspect
@@ -22,43 +22,37 @@ module Gradient
22
22
  @css_printer.css(**args)
23
23
  end
24
24
 
25
- private def expand_points
26
- new_points = @locations.map do |location|
25
+ private def merge_color_and_opacity_points
26
+ @locations.map do |location|
27
27
  selected_points = @all_points.select { |point| point.location == location }
28
- colored_points, opacity_points = selected_points.group_by(&:class).values_at(ColorPoint, OpacityPoint)
29
- if colored_points && opacity_points
30
- Gradient::Point.new(location, colored_points.first.color, opacity_points.first.opacity)
31
- elsif colored_points
32
- point = colored_points.first
33
- a, b = previous_and_next_in(@opacity_points, point)
28
+ colored, opaque = selected_points.group_by(&:class).values_at(ColorPoint, OpacityPoint)
29
+ rgba = if colored && opaque
30
+ [colored.first.color, opaque.first.opacity]
31
+ elsif colored
32
+ point = colored.first
33
+ a, b = adjacent_points(@opacity_points, point)
34
34
  fraction = location_fraction(a, b, point)
35
- opacity = opacity_difference(fraction, a, b)
36
- Gradient::Point.new(location, point.color, opacity)
37
- elsif opacity_points
38
- point = opacity_points.first
39
- a, b = previous_and_next_in(@color_points, point)
35
+ [point.color, opacity_difference(fraction, a, b)]
36
+ elsif opaque
37
+ point = opaque.first
38
+ a, b = adjacent_points(@color_points, point)
40
39
  fraction = location_fraction(a, b, point)
41
- color = color_difference(fraction, a, b)
42
- Gradient::Point.new(location, color, point.opacity)
40
+ [color_difference(fraction, a, b), point.opacity]
43
41
  end
42
+
43
+ Gradient::Point.new(location, *rgba)
44
44
  end
45
45
  end
46
46
 
47
- private def previous_and_next_in(bucket, point)
48
- groups = bucket.group_by { |p| point_group(p, point) }
47
+ private def adjacent_points(bucket, point)
48
+ groups = bucket.group_by { |p| triage_point(p, point) }
49
49
  a = groups.fetch(:same) { groups.fetch(:less) { groups.fetch(:more) } }.max { |p| p.location }
50
50
  b = groups.fetch(:same) { groups.fetch(:more) { groups.fetch(:less) } }.min { |p| p.location }
51
51
  return a, b
52
52
  end
53
53
 
54
- private def point_group(a, b)
55
- if a.location < b.location
56
- :less
57
- elsif a.location > b.location
58
- :more
59
- else
60
- :same
61
- end
54
+ private def triage_point(a, b)
55
+ a.location < b.location ? :less : (a.location > b.location ? :more : :same)
62
56
  end
63
57
 
64
58
  private def color_difference(fraction, a, b)
@@ -1,3 +1,3 @@
1
1
  module Gradient
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gradient
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philip Vieira
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-19 00:00:00.000000000 Z
11
+ date: 2015-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: color