color_picker 0.1.3 → 0.1.4

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: 429a2e8286798677c460a201fdd4450fbf2fb4b8
4
- data.tar.gz: f136bbb6b36d74e3487f7cab7807e4eb33485466
3
+ metadata.gz: 688441a3c2b18df6cb7423c68107ff963d643596
4
+ data.tar.gz: 95f2dc0db78f718e18ce17751f2c8740fe92de71
5
5
  SHA512:
6
- metadata.gz: 067cc616b32cd0406e11360f568b0a31edbfc53be6df20fc81267d1919dba6b2d855734af0555b04d10c369c3caf0fcea58f942d135d1422522a8ab053e8f26f
7
- data.tar.gz: 2c9f23cd121f6522c076a9ecccfe24e2ba0611b0bf51a4c7789734aeddc27aac59e3707789813d44cc4af1be5291d0d280a52ae2b171c10a46a0521758340fb5
6
+ metadata.gz: bba85bb1fdaa8655c61bb615649b11c9f2196ad9a37fc75f0a5b8b03b622c2e1f3f96ac36239f8d3ed93bb5c0477ae0f517fe2e09bc90b9f807879a7a7f2b35d
7
+ data.tar.gz: db254e4aa82dcdebc6d215bab337074e93084bd659203f43362b6b788167fd8b5f7cf6b196a2d5fa0d468eef886af873a70415d0171fa6621fb0cd5d14b6f599
@@ -50,6 +50,10 @@
50
50
  * depreacate default options in palette
51
51
  ### VERSION 0.1.3
52
52
  * add to s method
53
+ ### Version 0.1.4
54
+ * refactor of palette and color class @alejandrogutierrez
55
+ * refactor html method
56
+ * rename strong to dark palette
53
57
 
54
58
 
55
59
 
data/README.md CHANGED
@@ -19,9 +19,9 @@ a tool to get a color based on color palette, also have a method to export to ht
19
19
  @palette.sample_color
20
20
  > #<ColorPicker::Color:0x007f4dc236ac10 @hex_code="000000">
21
21
  ```
22
- * generate a strong palette
22
+ * generate a dark palette
23
23
  ```ruby
24
- @palette.generate(template: :strong)
24
+ @palette.generate(template: :dark)
25
25
  > [0..7, 0..9, 0..255]
26
26
  ```
27
27
 
@@ -8,12 +8,12 @@ module ColorPicker
8
8
 
9
9
  def to_rgb
10
10
  return code if rgb?
11
- code.scan(/.{2}/).map { |n| n.to_i(16) }
11
+ Color.new code.scan(/.{2}/).map { |n| n.to_i(16) }
12
12
  end
13
13
 
14
14
  def to_hex
15
15
  return code if hex?
16
- code.map { |n| n.to_s(16) }.join.rjust(6, '0')
16
+ Color.new code.map { |n| n.to_s(16) }.join.rjust(6, '0')
17
17
  end
18
18
 
19
19
  def hex?
@@ -1,7 +1,7 @@
1
1
  module ColorPicker
2
2
  class Palette
3
3
 
4
- attr_accessor :template, :colors
4
+ attr_accessor :template, :colors, :html
5
5
 
6
6
  def initialize(template: :default, colors: {})
7
7
  @template = template
@@ -13,7 +13,48 @@ module ColorPicker
13
13
  end
14
14
 
15
15
  def sample_color
16
- Color.new(ranges.map { |range| range.to_a.sample })
16
+ Color.new(ranges.map { |range| get_shade(range) })
17
17
  end
18
+
19
+ def max_number_of_colors
20
+ result = 1
21
+ ranges.each{|range| result *= range.end}
22
+ result
23
+ end
24
+
25
+ def html
26
+ @html ||= to_html
27
+ end
28
+
29
+ private
30
+ def get_shade(range)
31
+ (range.to_a.sample * (SHADES[template] || 1)).round
32
+ end
33
+
34
+ def to_html
35
+ _times = max_number_of_colors > 100 ? 100 : max_number_of_colors
36
+ html_content = HTML[:header]
37
+ html_content += "<head><table cellpadding='0' cellspacing='0' border='0' id='random_colors'><tbody><tr border-top:1px solid #fff; border-bottom:1px solid #fff>"
38
+ new_tr = nil
39
+ _times.times do |n|
40
+ html_content += "<tr border-top:1px solid #fff; border-bottom:1px solid #fff>" if new_tr
41
+ html_content += "<td style='background:#{sample_color.to_hex};color:#fff;width:55px;border-right:1px solid #fff;border-left:1px solid #fff;text-align:center;line-height:26px'>#{sample_color.to_hex}</td>"
42
+ if (n+1) % 5 == 0
43
+ html_content += "</tr>"
44
+ new_tr = true
45
+ else
46
+ new_tr = false
47
+ end
48
+ end
49
+ html_content += "</tbody></table>" + HTML[:footer]
50
+ generate_file html_content
51
+ end
52
+
53
+ def generate_file(content)
54
+ file = File.open("palette_#{template}.html", 'w')
55
+ file.write content
56
+ file.close
57
+ file.path
58
+ end
18
59
  end
19
60
  end
@@ -2,7 +2,14 @@ module ColorPicker
2
2
  class Palette
3
3
  TEMPLATES = {
4
4
  default: { red: 0..255, green: 0..255, blue: 0..255 },
5
- strong: { red: 0..7, green: 0..9, blue: 0..255}
5
+ dark: { red: 0..76, green: 0..94, blue: 0..255}
6
+ }
7
+ SHADES = {
8
+ dark: 0.6
9
+ }
10
+ HTML = {
11
+ header: '<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/><title>Palete</title><body>',
12
+ footer: '</body></html>'
6
13
  }
7
14
  end
8
15
  end
@@ -1,3 +1,3 @@
1
1
  module ColorPicker
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -13,13 +13,18 @@ module ColorPicker
13
13
  end
14
14
 
15
15
  def test_to_rgb
16
- assert_equal [0,0,0], @hex_color.to_rgb
16
+ assert_kind_of Color, @hex_color.to_rgb
17
17
  assert_equal [0,0,0], @rgb_color.to_rgb
18
18
  end
19
19
 
20
20
  def test_to_hex
21
- assert_equal '000000', @hex_color.to_hex
22
- assert_equal '000000', @rgb_color.to_hex
21
+ assert_equal "000000", @hex_color.to_hex
22
+ assert_kind_of Color, @rgb_color.to_hex
23
+ end
24
+
25
+ def test_method_chain
26
+ assert_equal "000000", @rgb_color.to_hex.code
27
+ assert_equal [0,0,0], @hex_color.to_rgb.code
23
28
  end
24
29
 
25
30
  def test_to_s
@@ -4,7 +4,7 @@ module ColorPicker
4
4
  class PaletteTest < Minitest::Test
5
5
  def setup
6
6
  @palette = ColorPicker::Palette.new
7
- @strong_palette = ColorPicker::Palette.new(template: :strong)
7
+ @dark_palette = ColorPicker::Palette.new(template: :dark)
8
8
  end
9
9
 
10
10
  def test_default_palette
@@ -12,9 +12,9 @@ module ColorPicker
12
12
  assert_equal ({ red: 0..255, green: 0..255, blue: 0..255 }), @palette.colors
13
13
  end
14
14
 
15
- def test_strong_palette
16
- assert_equal :strong, @strong_palette.template
17
- assert_equal ({ red: 0..7, green: 0..9, blue: 0..255 }), @strong_palette.colors
15
+ def test_dark_palette
16
+ assert_equal :dark, @dark_palette.template
17
+ assert_equal ({ red: 0..76, green: 0..94, blue: 0..255 }), @dark_palette.colors
18
18
  end
19
19
 
20
20
  def test_custom_palette
@@ -26,5 +26,10 @@ module ColorPicker
26
26
  def test_sample_color
27
27
  assert_kind_of Color, @palette.sample_color
28
28
  end
29
+
30
+ def test_html
31
+ @custom_palette = ColorPicker::Palette.new(colors: { red: 0..1, green: 1..2, blue: 5..14 })
32
+ assert_equal "palette_default.html", @palette.html
33
+ end
29
34
  end
30
35
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: color_picker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bernardo Galindo