pigment 0.1.10 → 0.2.0

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.
Files changed (2) hide show
  1. data/lib/pigment.rb +18 -20
  2. metadata +8 -6
data/lib/pigment.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Pigment
2
- VERSION = '0.1.10'
2
+ VERSION = '0.2.0'
3
3
 
4
4
  class Color
5
5
 
@@ -27,20 +27,16 @@ module Pigment
27
27
  end
28
28
  end
29
29
 
30
- # Selectors.
30
+ # Selectors and Setters.
31
31
  %w'r g b a'.each_with_index do |m, i|
32
- define_method("#{m}", ->() { color[i] })
32
+ define_method("#{m}", ->() { @color[i] })
33
+ define_method("#{m}=", ->(value) { @color[i] = value if value.is_a?(Float) && (0.0..1.0).include?(value) })
33
34
  end
34
35
 
35
36
  %w'h s l'.each_with_index do |m, i|
36
37
  define_method("#{m}", ->() { hsl[i] })
37
38
  end
38
39
 
39
- # Set alpha value. Only accepts float values
40
- # @param [Float] alpha
41
- def a=(alpha)
42
- @color[3] = alpha if alpha.is_a?(Float) && (0.0..1.0).include?(alpha)
43
- end
44
40
 
45
41
  # Returns an array with the rgb components
46
42
  # @return [Array]
@@ -48,11 +44,6 @@ module Pigment
48
44
  @color[0, 3]
49
45
  end
50
46
 
51
- def hsl
52
- to_hsl unless @hsl
53
- @hsl
54
- end
55
-
56
47
  # Return specified color by its name from the named_colors hash.
57
48
  # @param [Symbol] name
58
49
  # @return [Color]
@@ -179,6 +170,11 @@ module Pigment
179
170
  color.is_a?(Color) && color.rgb == rgb
180
171
  end
181
172
 
173
+ # @return [Color]
174
+ def dup
175
+ self.class.new(*@color)
176
+ end
177
+
182
178
  # Converts a color to its grayscale correspondent
183
179
  # @return [Color]
184
180
  def grayscale
@@ -227,10 +223,11 @@ module Pigment
227
223
  # @param [Array of Symbols] channels
228
224
  # @return [Color]
229
225
  def remove_channels(*channels)
230
- r = 0 if channels.include? :r
231
- g = 0 if channels.include? :g
232
- b = 0 if channels.include? :b
233
- self.class.new(r, g, b)
226
+ color = self.class.new(r, g, b, a)
227
+ %w'r g b a'.each do |attr|
228
+ color.send("#{attr}=", 0) if channels.include? attr.to_sym
229
+ end
230
+ color
234
231
  end
235
232
 
236
233
  # Creates an instance variable to keep the HSL values of a RGB color.
@@ -269,21 +266,21 @@ module Pigment
269
266
  # Returns an array of the color components. Alpha value is passed as well if with_alpha is set to true.
270
267
  # @param [Boolean] with_alpha
271
268
  # @return [Array]
272
- def to_floats(with_alpha = false)
269
+ def to_floats(with_alpha = true)
273
270
  with_alpha ? @color.dup : rgb
274
271
  end
275
272
 
276
273
  # Returns an array of the color components. Alpha value is passed as well if with_alpha is set to true.
277
274
  # @param [Boolean] with_alpha
278
275
  # @return [Array]
279
- def to_ints(with_alpha = false)
276
+ def to_ints(with_alpha = true)
280
277
  to_floats(with_alpha).map { |v| Integer(v * 255) }
281
278
  end
282
279
 
283
280
  # Returns an array of the color components. Alpha value is passed as well if with_alpha is set to true.
284
281
  # @param [Boolean] with_alpha
285
282
  # @return [Array]
286
- def to_hex(with_alpha = false)
283
+ def to_hex(with_alpha = true)
287
284
  to_ints(with_alpha).map { |v| '%02x' % v }.join
288
285
  end
289
286
 
@@ -303,6 +300,7 @@ module Pigment
303
300
  alias_method :to_a, :to_floats
304
301
  alias_method :to_ary, :to_floats
305
302
  alias_method :to_f, :to_floats
303
+ alias_method :to_hsl, :hsl
306
304
  end
307
305
  end
308
306
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pigment
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-12-22 00:00:00.000000000 Z
13
+ date: 2012-12-28 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description: A rgb color gem, with a list of 750 different colors defined within 869
16
16
  names.
@@ -26,11 +26,13 @@ files:
26
26
  - README.md
27
27
  homepage: https://github.com/P3t3rU5/pigment
28
28
  licenses: []
29
- post_install_message: ! "+---------------------------------------------------+\n Thanks
30
- for choosing Pigment.\n\n =================================================\n 0.1.10
31
- Changes:\n - Fixed to_floats to use dup.\n - Added Transparent Color\n =================================================\n\n
29
+ post_install_message: ! "+----------------------------------------------------------------------------+\n
30
+ \ Thanks for choosing Pigment.\n\n ==========================================================================\n
31
+ \ 0.2.0 Changes:\n - WARNING: Color#to_floats now returns alpha by default\n
32
+ \ - Added Color#dup\n - Dynamically defined setters for r, g and b\n - Removed
33
+ Color#hsl\n - Corrected Color#remove_channels\n ==========================================================================\n\n
32
34
  \ If you like what you see, support us on Pledgie:\n http://www.pledgie.com/campaigns/18945\n\n
33
- \ If you find any bugs, please report them on\n https://github.com/P3t3rU5/pigment/issues\n\n+---------------------------------------------------+\n"
35
+ \ If you find any bugs, please report them on\n https://github.com/P3t3rU5/pigment/issues\n\n+----------------------------------------------------------------------------+\n"
34
36
  rdoc_options: []
35
37
  require_paths:
36
38
  - lib