immosquare-colors 0.1.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b5be0c3984d5ad49b9d88bc8b256d97ef15d94bcdef1edcbdb1802a9de7a6f30
4
+ data.tar.gz: 728240a213ab7b71f3d0c9fa1a262c18ac9cc7aa52a5b3f256d9af434e2c71c9
5
+ SHA512:
6
+ metadata.gz: e2ae6d332d4a7b94a1ccf8f1505ee06e7b76fac2ce1e70d1729e94cafdec9cfe79b1fbc8346e04e60dbfdf7ed4534ee5322178fffeffcd25bb3f01a6493166fc
7
+ data.tar.gz: 10b9dfdf33f4729316234be56a668e92d0e3cd7a5e0f903ac09209c1aedad6dc0cfb9c3b30fa82a13a522ddacdcd35739b8c934a5ec02e2919520e20ca09f79c
@@ -0,0 +1,3 @@
1
+ module ImmosquareColors
2
+ VERSION = "0.1.1".freeze
3
+ end
@@ -0,0 +1,206 @@
1
+ module ImmosquareColors
2
+ class << self
3
+
4
+ ##============================================================##
5
+ ## To determine whether the complementary color should be
6
+ ## black or white
7
+ ##============================================================##
8
+ def get_complementary_color(color, options = {})
9
+ begin
10
+ luminance_std = (options[:luminance] || 127.5).to_f
11
+ black = "#000000"
12
+ white = "#FFFFFF"
13
+ color_hex = color.start_with?("#") ? color : color_name_to_hex(color)
14
+
15
+ raise("Not valid size") if ![7, 9].include?(color_hex.length)
16
+
17
+
18
+ color_rgba = hex_to_rgba(color_hex)
19
+ r, g, b, a = color_rgba
20
+
21
+ ##============================================================##
22
+ ## luminance calculation
23
+ ##============================================================##
24
+ luminance = Math.sqrt((0.299 * (r**2)) + (0.587 * (g**2)) + (0.114 * (b**2)))
25
+ luminance > luminance_std ? black : white
26
+ rescue StandardError => e
27
+ puts("=== Error! ===")
28
+ puts(e.message)
29
+ puts(e.backtrace)
30
+ black
31
+ end
32
+ end
33
+
34
+ ##============================================================##
35
+ ## To transform a hex color to rgba
36
+ ##============================================================##
37
+ def hex_to_rgba(hex_color)
38
+ hex_color = hex_color.gsub("#", "")
39
+ red = hex_color[0..1].to_i(16)
40
+ green = hex_color[2..3].to_i(16)
41
+ blue = hex_color[4..5].to_i(16)
42
+ rgba = [red, green, blue]
43
+ rgba += [(hex_color[6..7].to_i(16) / 255.0).round(2)] if hex_color.length == 8
44
+ rgba
45
+ end
46
+
47
+ ##============================================================##
48
+ ## A dictionary for mapping textual colors to colors
49
+ ## hex
50
+ ##============================================================##
51
+ def color_name_to_hex(color_name)
52
+ color_map = {
53
+ :aliceblue => "#f0f8ff",
54
+ :antiquewhite => "#faebd7",
55
+ :aqua => "#00ffff",
56
+ :aquamarine => "#7fffd4",
57
+ :azure => "#f0ffff",
58
+ :beige => "#f5f5dc",
59
+ :bisque => "#ffe4c4",
60
+ :black => "#000000",
61
+ :blanchedalmond => "#ffebcd",
62
+ :blue => "#0000ff",
63
+ :blueviolet => "#8a2be2",
64
+ :brown => "#a52a2a",
65
+ :burlywood => "#deb887",
66
+ :cadetblue => "#5f9ea0",
67
+ :chartreuse => "#7fff00",
68
+ :chocolate => "#d2691e",
69
+ :coral => "#ff7f50",
70
+ :cornflowerblue => "#6495ed",
71
+ :cornsilk => "#fff8dc",
72
+ :crimson => "#dc143c",
73
+ :cyan => "#00ffff",
74
+ :darkblue => "#00008b",
75
+ :darkcyan => "#008b8b",
76
+ :darkgoldenrod => "#b8860b",
77
+ :darkgray => "#a9a9a9",
78
+ :darkgreen => "#006400",
79
+ :darkgrey => "#a9a9a9",
80
+ :darkkhaki => "#bdb76b",
81
+ :darkmagenta => "#8b008b",
82
+ :darkolivegreen => "#556b2f",
83
+ :darkorange => "#ff8c00",
84
+ :darkorchid => "#9932cc",
85
+ :darkred => "#8b0000",
86
+ :darksalmon => "#e9967a",
87
+ :darkseagreen => "#8fbc8f",
88
+ :darkslateblue => "#483d8b",
89
+ :darkslategray => "#2f4f4f",
90
+ :darkslategrey => "#2f4f4f",
91
+ :darkturquoise => "#00ced1",
92
+ :darkviolet => "#9400d3",
93
+ :deeppink => "#ff1493",
94
+ :deepskyblue => "#00bfff",
95
+ :dimgray => "#696969",
96
+ :dimgrey => "#696969",
97
+ :dodgerblue => "#1e90ff",
98
+ :firebrick => "#b22222",
99
+ :floralwhite => "#fffaf0",
100
+ :forestgreen => "#228b22",
101
+ :fuchsia => "#ff00ff",
102
+ :gainsboro => "#dcdcdc",
103
+ :ghostwhite => "#f8f8ff",
104
+ :goldenrod => "#daa520",
105
+ :gold => "#ffd700",
106
+ :gray => "#808080",
107
+ :green => "#008000",
108
+ :greenyellow => "#adff2f",
109
+ :grey => "#808080",
110
+ :honeydew => "#f0fff0",
111
+ :hotpink => "#ff69b4",
112
+ :indianred => "#cd5c5c",
113
+ :indigo => "#4b0082",
114
+ :ivory => "#fffff0",
115
+ :khaki => "#f0e68c",
116
+ :lavenderblush => "#fff0f5",
117
+ :lavender => "#e6e6fa",
118
+ :lawngreen => "#7cfc00",
119
+ :lemonchiffon => "#fffacd",
120
+ :lightblue => "#add8e6",
121
+ :lightcoral => "#f08080",
122
+ :lightcyan => "#e0ffff",
123
+ :lightgoldenrodyellow => "#fafad2",
124
+ :lightgray => "#d3d3d3",
125
+ :lightgreen => "#90ee90",
126
+ :lightgrey => "#d3d3d3",
127
+ :lightpink => "#ffb6c1",
128
+ :lightsalmon => "#ffa07a",
129
+ :lightseagreen => "#20b2aa",
130
+ :lightskyblue => "#87cefa",
131
+ :lightslategray => "#778899",
132
+ :lightslategrey => "#778899",
133
+ :lightsteelblue => "#b0c4de",
134
+ :lightyellow => "#ffffe0",
135
+ :lime => "#00ff00",
136
+ :limegreen => "#32cd32",
137
+ :linen => "#faf0e6",
138
+ :magenta => "#ff00ff",
139
+ :maroon => "#800000",
140
+ :mediumaquamarine => "#66cdaa",
141
+ :mediumblue => "#0000cd",
142
+ :mediumorchid => "#ba55d3",
143
+ :mediumpurple => "#9370db",
144
+ :mediumseagreen => "#3cb371",
145
+ :mediumslateblue => "#7b68ee",
146
+ :mediumspringgreen => "#00fa9a",
147
+ :mediumturquoise => "#48d1cc",
148
+ :mediumvioletred => "#c71585",
149
+ :midnightblue => "#191970",
150
+ :mintcream => "#f5fffa",
151
+ :mistyrose => "#ffe4e1",
152
+ :moccasin => "#ffe4b5",
153
+ :navajowhite => "#ffdead",
154
+ :navy => "#000080",
155
+ :oldlace => "#fdf5e6",
156
+ :olive => "#808000",
157
+ :olivedrab => "#6b8e23",
158
+ :orange => "#ffa500",
159
+ :orangered => "#ff4500",
160
+ :orchid => "#da70d6",
161
+ :palegoldenrod => "#eee8aa",
162
+ :palegreen => "#98fb98",
163
+ :paleturquoise => "#afeeee",
164
+ :palevioletred => "#db7093",
165
+ :papayawhip => "#ffefd5",
166
+ :peachpuff => "#ffdab9",
167
+ :peru => "#cd853f",
168
+ :pink => "#ffc0cb",
169
+ :plum => "#dda0dd",
170
+ :powderblue => "#b0e0e6",
171
+ :purple => "#800080",
172
+ :rebeccapurple => "#663399",
173
+ :red => "#ff0000",
174
+ :rosybrown => "#bc8f8f",
175
+ :royalblue => "#4169e1",
176
+ :saddlebrown => "#8b4513",
177
+ :salmon => "#fa8072",
178
+ :sandybrown => "#f4a460",
179
+ :seagreen => "#2e8b57",
180
+ :seashell => "#fff5ee",
181
+ :sienna => "#a0522d",
182
+ :silver => "#c0c0c0",
183
+ :skyblue => "#87ceeb",
184
+ :slateblue => "#6a5acd",
185
+ :slategray => "#708090",
186
+ :slategrey => "#708090",
187
+ :snow => "#fffafa",
188
+ :springgreen => "#00ff7f",
189
+ :steelblue => "#4682b4",
190
+ :tan => "#d2b48c",
191
+ :teal => "#008080",
192
+ :thistle => "#d8bfd8",
193
+ :tomato => "#ff6347",
194
+ :turquoise => "#40e0d0",
195
+ :violet => "#ee82ee",
196
+ :wheat => "#f5deb3",
197
+ :white => "#ffffff",
198
+ :whitesmoke => "#f5f5f5",
199
+ :yellow => "#ffff00",
200
+ :yellowgreen => "#9acd32"
201
+ }
202
+ color_map[color_name.downcase.to_sym] || "#000000"
203
+ end
204
+
205
+ end
206
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: immosquare-colors
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - IMMO SQUARE
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-10-05 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Provides methods to suggest complementary colors based on luminance,
14
+ convert HEX to RGBA, and map named colors to HEX
15
+ email:
16
+ - jules@immosquare.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/immosquare-colors.rb
22
+ - lib/immosquare-colors/version.rb
23
+ homepage: https://github.com/IMMOSQUARE/immosquare-colors
24
+ licenses:
25
+ - MIT
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: 2.7.2
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubygems_version: 3.4.13
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: Ruby utility for complementary color derivation and color conversions.
46
+ test_files: []