color_swatch_collection 0.1.1 → 0.1.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.
@@ -4,6 +4,7 @@ require 'active_support/core_ext/object/blank'
4
4
  require 'active_support/core_ext/string/inflections'
5
5
 
6
6
  require_relative 'color_swatch_collection/version'
7
+ require_relative 'color_swatch_collection/configuration'
7
8
 
8
9
  require_relative 'color_swatch_collection/basic'
9
10
  require_relative 'color_swatch_collection/html'
@@ -27,13 +28,13 @@ module ColorSwatchCollection
27
28
  def self.get_from_hex(colour_hex, pick: [], omit: [])
28
29
  found_colour = nil
29
30
 
30
- self.list_collections.each do |list_name|
31
- next unless (pick.empty? || pick.include?(list_name)) && !omit.include?(list_name)
31
+ self.list_collections.each do |collection_name|
32
+ next unless self.check_collection_use(pick, omit, collection_name)
32
33
 
33
- found_colour = self.get_item_from_collection(colour_hex, 'hex', list_name)
34
+ found_colour = self.get_item_from_collection(colour_hex, 'hex', collection_name)
34
35
 
35
36
  if found_colour.present?
36
- found_colour[:collection] = list_name
37
+ found_colour[:collection] = collection_name
37
38
  break
38
39
  end
39
40
  end
@@ -44,13 +45,13 @@ module ColorSwatchCollection
44
45
  def self.get_from_name(colour_name, pick: [], omit: [])
45
46
  found_colour = nil
46
47
 
47
- self.list_collections.each do |list_name|
48
- next unless (pick.empty? || pick.include?(list_name)) && !omit.include?(list_name)
48
+ self.list_collections.each do |collection_name|
49
+ next unless self.check_collection_use(pick, omit, collection_name)
49
50
 
50
- found_colour = self.get_item_from_collection(colour_name, 'name', list_name)
51
+ found_colour = self.get_item_from_collection(colour_name, 'name', collection_name)
51
52
 
52
53
  if found_colour.present?
53
- found_colour[:collection] = list_name
54
+ found_colour[:collection] = collection_name
54
55
  break
55
56
  end
56
57
  end
@@ -59,11 +60,11 @@ module ColorSwatchCollection
59
60
  end
60
61
 
61
62
  def self.get_colours(pick: [], omit: [])
62
- self.list_collections.collect do |list_name|
63
- next unless (pick.empty? || pick.include?(list_name)) && !omit.include?(list_name)
63
+ self.list_collections.collect do |collection_name|
64
+ next unless self.check_collection_use(pick, omit, collection_name)
64
65
 
65
- Object.const_get("ColorSwatchCollection::#{list_name.classify}").colours.collect do |swatch_hash|
66
- swatch_hash[:collection] = list_name
66
+ Object.const_get("ColorSwatchCollection::#{collection_name.classify}").colours.collect do |swatch_hash|
67
+ swatch_hash[:collection] = collection_name
67
68
  swatch_hash
68
69
  end
69
70
  end.compact.flatten
@@ -71,16 +72,26 @@ module ColorSwatchCollection
71
72
 
72
73
  private
73
74
 
74
- def self.get_item_from_collection(colour_input, input_type, list_name)
75
+ def self.check_collection_use(pick, omit, collection_name)
76
+ pick = ColorSwatchCollection.configuration.default_collection_picks if pick.empty?
77
+ omit = ColorSwatchCollection.configuration.default_collection_omits if omit.empty?
78
+
79
+ pick = [] if pick == ['[]']
80
+ omit = [] if omit == ['[]']
81
+
82
+ (pick.empty? || pick.include?(collection_name)) && !omit.include?(collection_name)
83
+ end
84
+
85
+ def self.get_item_from_collection(colour_input, input_type, collection_name)
75
86
  return nil if colour_input.blank?
76
87
 
77
88
  swatch_hash = nil
78
- list_collection_object = Object.const_get("ColorSwatchCollection::#{list_name.classify}")
89
+ list_collection_object = Object.const_get("ColorSwatchCollection::#{collection_name.classify}")
79
90
 
80
91
  if input_type == 'hex'
81
92
  swatch_hash = list_collection_object.colours.find { |swatch| swatch[:hex] == colour_input.upcase }
82
93
  elsif input_type == 'name'
83
- if ['ntc', 'pantone'].include?(list_name)
94
+ if ['ntc', 'pantone'].include?(collection_name)
84
95
  swatch_hash = list_collection_object.colours.find { |swatch| swatch[:name] == colour_input.downcase.strip }
85
96
  else
86
97
  swatch_hash = list_collection_object.colours.find { |swatch| swatch[:name] == colour_input.downcase.gsub(' ', '') }
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: color_swatch_collection
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Louis Davis
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-08-27 00:00:00.000000000 Z
10
+ date: 2025-08-31 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: activesupport
@@ -35,6 +35,7 @@ files:
35
35
  - Rakefile
36
36
  - lib/color_swatch_collection.rb
37
37
  - lib/color_swatch_collection/basic.rb
38
+ - lib/color_swatch_collection/configuration.rb
38
39
  - lib/color_swatch_collection/html.rb
39
40
  - lib/color_swatch_collection/ntc.rb
40
41
  - lib/color_swatch_collection/pantone.rb
@@ -66,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
67
  - !ruby/object:Gem::Version
67
68
  version: '0'
68
69
  requirements: []
69
- rubygems_version: 3.6.3
70
+ rubygems_version: 3.6.5
70
71
  specification_version: 4
71
72
  summary: A collection of colour swatches from various palettes and their corresponding
72
73
  hex value.