carrierwave-color 1.0.1 → 1.0.2

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: 62d10a7dd55d5bebfbe5ee8592ce6fb6dd8dadd6
4
- data.tar.gz: 9f425d1ce557654002f0bae34582469e6d172ab2
3
+ metadata.gz: 1b6fc42d5e7ce84c7e1c44872f3a3342980435cd
4
+ data.tar.gz: f8ce682015304674dde3184d29467444f27df637
5
5
  SHA512:
6
- metadata.gz: 6b9cf6e341455d0e5b12a919af205993f36743f87ecb3899900a576b064f705ec1aca6e59954c2738692f2c55fcbed61e0adf3bef2b73d5abeb123e24c909fbe
7
- data.tar.gz: 58f49f327bbb5d3842b7551d93fa99d9b790b5feb46f35ac6e4b1b89cd6c27a31a57edbe25fd8a2cb51264d73861729e3c9caa694381433fc60777624ac191e8
6
+ metadata.gz: 583b69fa74bc3c3d66c805d532d160f011fefabf73e2aca5887bcfc3f1b11e470a1c5d9911d1c06a36ef70f01ec9cb33b24da13c2254c231a008148c21f74d05
7
+ data.tar.gz: b4f5a905ae31fbc9ff50b3ca86fd8d9cf55738e37f389f156c9b65d6937fb8ad7225603dfe104386d27e15fdcd4a0e8e6490e3cea99aa94631d3c482aa8b563e
@@ -0,0 +1 @@
1
+ 2.3.1
data/README.md CHANGED
@@ -10,9 +10,10 @@ or to index images for a "search by color" feature.
10
10
  Installation
11
11
  ------------
12
12
 
13
- Add this line to your application's Gemfile:
13
+ Add the following lines to your application's Gemfile:
14
14
 
15
15
  ```ruby
16
+ # Detect the dominant color of images on upload
16
17
  gem "carrierwave-color"
17
18
  ```
18
19
 
@@ -12,13 +12,14 @@ module CarrierWave
12
12
  end
13
13
 
14
14
  def dominant_from_palette_html(path, palette_hexes)
15
- histogram = Colorscore::Histogram.new(path)
15
+ scores = Colorscore::Histogram.new(path).scores
16
16
  palette = Colorscore::Palette.from_hex(palette_hexes)
17
17
 
18
- histogram_scores = histogram.scores
19
- return nil if histogram_scores.first.last.nil?
18
+ # Return nil values from scores
19
+ scores.reject! { |_color_score, color| color.nil? }
20
+ return nil if scores.empty?
20
21
 
21
- scores = palette.scores(histogram_scores, 1)
22
+ scores = palette.scores(scores, 1)
22
23
  _score, color = scores.first
23
24
  color.html
24
25
  end
@@ -1,5 +1,5 @@
1
1
  module CarrierWave
2
2
  module Color
3
- VERSION = "1.0.1"
3
+ VERSION = "1.0.2"
4
4
  end
5
5
  end
@@ -4,6 +4,7 @@ module CarrierWave
4
4
  module Color
5
5
  RSpec.describe Detection do
6
6
  let(:path) { File.expand_path('../fixtures/red-rainbow.jpg', __FILE__) }
7
+ let(:blue_color) { ::Color::RGB.from_html("0066cc") }
7
8
 
8
9
  describe ".dominant_html" do
9
10
  it "returns the correct hex code" do
@@ -20,12 +21,21 @@ module CarrierWave
20
21
 
21
22
  it "returns nil when the histogram fails" do
22
23
  allow_any_instance_of(Colorscore::Histogram).to receive(:scores)
23
- .and_return([[1, nil]])
24
+ .and_return([[1, nil], [1, nil]])
24
25
 
25
26
  palette = %w(ff0000 00ff00 0000ff)
26
27
  result = Detection.dominant_from_palette_html(path, palette)
27
28
  expect(result).to be_nil
28
29
  end
30
+
31
+ it "returns the only color found if the histogram contains any color" do
32
+ allow_any_instance_of(Colorscore::Histogram).to receive(:scores)
33
+ .and_return([[1, blue_color], [1, nil]])
34
+
35
+ palette = %w(ff0000 00ff00 0000ff)
36
+ result = Detection.dominant_from_palette_html(path, palette)
37
+ expect(result).to eq("#0000ff")
38
+ end
29
39
  end
30
40
  end
31
41
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrierwave-color
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sunny Ripert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-31 00:00:00.000000000 Z
11
+ date: 2017-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorscore
@@ -75,6 +75,7 @@ extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
77
77
  - ".gitignore"
78
+ - ".ruby-version"
78
79
  - Gemfile
79
80
  - README.md
80
81
  - Rakefile
@@ -106,9 +107,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
107
  version: '0'
107
108
  requirements: []
108
109
  rubyforge_project:
109
- rubygems_version: 2.4.5
110
+ rubygems_version: 2.5.1
110
111
  signing_key:
111
112
  specification_version: 4
112
113
  summary: Store the dominant color of an image with CarrierWave
113
114
  test_files: []
114
- has_rdoc: