hex_color_generate 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +13 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +56 -0
- data/Rakefile +12 -0
- data/hex_color_generate.gemspec +38 -0
- data/lib/hex_color_generate/class_methods.rb +61 -0
- data/lib/hex_color_generate/colors.rb +155 -0
- data/lib/hex_color_generate/version.rb +5 -0
- data/lib/hex_color_generate.rb +11 -0
- data/sig/hex_color_generate.rbs +4 -0
- metadata +58 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a90d833cce24fbc0b170e16e44f0b826819dbc42093ad5f7453c9b7f899ed8be
|
4
|
+
data.tar.gz: ef8eae0496eb32d480572363233456da5426b151bc67dd483086689de85eaba5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cf3cb29a996b74720b487bb608e6e2c1ac49eba86b40b34edd82a986db376f87a15ed61ca06159dea90f236a48c35ab0787cbe9490b9aeb87ad611638f1c7cbb
|
7
|
+
data.tar.gz: f0ac7a2f3c029febd5c2147ee2391bf1a750411d35caa73649609fec17fe3099868feffbe0d731ab202a2222c8dd37001ed8101e949bfcf0e40b5a6311565a82
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/CHANGELOG.md
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 Alef Ojeda de Oliveira
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# HexColorGenerate
|
2
|
+
|
3
|
+
This gem is used to generate random hex color codes. It can be used to generate a single color or a list of colors. It can also be used to generate a list of colors with a specific color as the base color. The gem also provides a method to generate a list of colors with a specific color as the base color and a specific number of colors to be generated.
|
4
|
+
|
5
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/hex_color_generate`. To experiment with that code, run `bin/console` for an interactive prompt.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Install the gem and add to the application's Gemfile by executing:
|
10
|
+
|
11
|
+
$ bundle add hex_color_generate
|
12
|
+
|
13
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
14
|
+
|
15
|
+
$ gem install hex_color_generate
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
### Generate a single color
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
# Generate a random hex color code
|
23
|
+
HexColorGenerate.generate
|
24
|
+
|
25
|
+
# Generate a random hex color code with a specific color as the base color
|
26
|
+
HexColorGenerate.generate(color: :red)
|
27
|
+
|
28
|
+
# Get all the colors available
|
29
|
+
HexColorGenerate.colors # => ["white", "red", "blue", "green", ...]
|
30
|
+
|
31
|
+
# Generate a color specific
|
32
|
+
HexColorGenerate.red
|
33
|
+
|
34
|
+
# Generate a color specific with a specific color as the base color
|
35
|
+
HexColorGenerate.red(type: "salmon")
|
36
|
+
|
37
|
+
# Get types of colors available for a specific color (red)
|
38
|
+
HexColorGenerate.red_keys # => ["salmon", "dark_salmon", "light_salmon", "crimson", "red", ...]
|
39
|
+
|
40
|
+
# Get values of colors available for a specific color (red)
|
41
|
+
HexColorGenerate.red_values # => [{:salmon=>"#FA8072"}, {:dark_salmon=>"#E9967A"}, ...]
|
42
|
+
```
|
43
|
+
|
44
|
+
## Development
|
45
|
+
|
46
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
47
|
+
|
48
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
49
|
+
|
50
|
+
## Contributing
|
51
|
+
|
52
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/hex_color_generate.
|
53
|
+
|
54
|
+
## License
|
55
|
+
|
56
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/hex_color_generate/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "hex_color_generate"
|
7
|
+
spec.version = HexColorGenerate::VERSION
|
8
|
+
spec.authors = ["Alef Ojeda de Oliveira"]
|
9
|
+
spec.email = ["alef.oliveira@dimensa.com.br"]
|
10
|
+
|
11
|
+
spec.summary = "Generate hexadecimal color"
|
12
|
+
spec.description = "This gem generate hexadecimal color"
|
13
|
+
spec.homepage = "https://github.com/nemuba/hex_color_generate"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 2.7.1"
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = "https://github.com/nemuba/hex_color_generate"
|
18
|
+
spec.metadata["source_code_uri"] = "https://github.com/nemuba/hex_color_generate/tree/main"
|
19
|
+
spec.metadata["changelog_uri"] = "https://github.com/nemuba/hex_color_generate/blob/main/CHANGELOG.md"
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(__dir__) do
|
24
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
25
|
+
(File.expand_path(f) == __FILE__) ||
|
26
|
+
f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile])
|
27
|
+
end
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
# Uncomment to register a new dependency of your gem
|
34
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
35
|
+
|
36
|
+
# For more information and examples about making a new gem, check out our
|
37
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
38
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "colors"
|
4
|
+
|
5
|
+
# HexColorGenerate module
|
6
|
+
module HexColorGenerate
|
7
|
+
# ClassMethods module
|
8
|
+
module ClassMethods
|
9
|
+
include ::HexColorGenerate::Colors
|
10
|
+
|
11
|
+
# generate random color
|
12
|
+
# @param color [Symbol] type of color
|
13
|
+
# @return [String] hex color
|
14
|
+
def generate(color: nil)
|
15
|
+
random = color || COLORS.keys.sample
|
16
|
+
color = COLORS[random].keys.sample
|
17
|
+
send(random, type: color)
|
18
|
+
end
|
19
|
+
|
20
|
+
# get all colors
|
21
|
+
# @return [Array] array of colors
|
22
|
+
def colors
|
23
|
+
COLORS.keys
|
24
|
+
end
|
25
|
+
|
26
|
+
COLORS.each do |color, types|
|
27
|
+
# define method with param type with default value color
|
28
|
+
# @param type [Symbol] type of color
|
29
|
+
# @return [String] hex color
|
30
|
+
define_method color do |type: color|
|
31
|
+
colors = types.freeze
|
32
|
+
color = colors[type.to_s]
|
33
|
+
raise ArgumentError, "Invalid color type: #{type}" unless color
|
34
|
+
|
35
|
+
format_color(color)
|
36
|
+
end
|
37
|
+
|
38
|
+
# define method to get all colors of type
|
39
|
+
# @return [Array] array of colors
|
40
|
+
define_method "#{color}_keys" do
|
41
|
+
types.keys.map(&:to_sym)
|
42
|
+
end
|
43
|
+
|
44
|
+
# define method to get all colors of type
|
45
|
+
# @return [Hash] hash of colors
|
46
|
+
define_method "#{color}_values" do
|
47
|
+
# transforma values and symbolize keys
|
48
|
+
types.transform_keys(&:to_sym).transform_values(&method(:format_color))
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
# format color to hex
|
55
|
+
# @param color [String] color
|
56
|
+
# @return [String] hex color
|
57
|
+
def format_color(color)
|
58
|
+
"##{color}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,155 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module HexColorGenerate
|
4
|
+
module Colors
|
5
|
+
COLORS = {
|
6
|
+
red: {
|
7
|
+
"indianred" => "cd5c5c",
|
8
|
+
"lightcoral" => "f08080",
|
9
|
+
"salmon" => "fa8072",
|
10
|
+
"darksalmon" => "e9967a",
|
11
|
+
"lightsalmon" => "ffa07a",
|
12
|
+
"crimson" => "dc143c",
|
13
|
+
"red" => "ff0000",
|
14
|
+
"firebrick" => "b22222",
|
15
|
+
"darkred" => "8b0000"
|
16
|
+
},
|
17
|
+
green: {
|
18
|
+
"lime" => "00ff00",
|
19
|
+
"limegreen" => "32cd32",
|
20
|
+
"forestgreen" => "228b22",
|
21
|
+
"green" => "008000",
|
22
|
+
"darkgreen" => "006400"
|
23
|
+
},
|
24
|
+
blue: {
|
25
|
+
"aqua" => "00ffff",
|
26
|
+
"cyan" => "00ffff",
|
27
|
+
"lightcyan" => "e0ffff",
|
28
|
+
"paleturquoise" => "afeeee",
|
29
|
+
"aquamarine" => "7fffd4",
|
30
|
+
"turquoise" => "40e0d0",
|
31
|
+
"mediumturquoise" => "48d1cc",
|
32
|
+
"darkturquoise" => "00ced1",
|
33
|
+
"lightseagreen" => "20b2aa",
|
34
|
+
"cadetblue" => "5f9ea0",
|
35
|
+
"darkcyan" => "008b8b",
|
36
|
+
"teal" => "008080",
|
37
|
+
"blue" => "0000ff",
|
38
|
+
"mediumblue" => "0000cd",
|
39
|
+
"darkblue" => "00008b",
|
40
|
+
"navy" => "000080",
|
41
|
+
"midnightblue" => "191970"
|
42
|
+
},
|
43
|
+
yellow: {
|
44
|
+
"yellow" => "ffff00",
|
45
|
+
"lightyellow" => "ffffe0",
|
46
|
+
"lemonchiffon" => "fffacd",
|
47
|
+
"lightgoldenrodyellow" => "fafad2",
|
48
|
+
"papayawhip" => "ffefd5",
|
49
|
+
"moccasin" => "ffe4b5",
|
50
|
+
"peachpuff" => "ffdab9",
|
51
|
+
"palegoldenrod" => "eee8aa",
|
52
|
+
"khaki" => "f0e68c",
|
53
|
+
"darkkhaki" => "bdb76b",
|
54
|
+
"gold" => "ffd700"
|
55
|
+
},
|
56
|
+
orange: {
|
57
|
+
"orange" => "ffa500",
|
58
|
+
"darkorange" => "ff8c00",
|
59
|
+
"coral" => "ff7f50",
|
60
|
+
"tomato" => "ff6347",
|
61
|
+
"orangered" => "ff4500",
|
62
|
+
"gold" => "ffd700"
|
63
|
+
},
|
64
|
+
purple: {
|
65
|
+
"lavender" => "e6e6fa",
|
66
|
+
"thistle" => "d8bfd8",
|
67
|
+
"plum" => "dda0dd",
|
68
|
+
"violet" => "ee82ee",
|
69
|
+
"orchid" => "da70d6",
|
70
|
+
"fuchsia" => "ff00ff",
|
71
|
+
"magenta" => "ff00ff",
|
72
|
+
"mediumorchid" => "ba55d3",
|
73
|
+
"mediumpurple" => "9370db",
|
74
|
+
"blueviolet" => "8a2be2",
|
75
|
+
"darkviolet" => "9400d3",
|
76
|
+
"darkorchid" => "9932cc",
|
77
|
+
"darkmagenta" => "8b008b",
|
78
|
+
"purple" => "800080",
|
79
|
+
"indigo" => "4b0082",
|
80
|
+
"darkslateblue" => "483d8b",
|
81
|
+
"slateblue" => "6a5acd",
|
82
|
+
"mediumslateblue" => "7b68ee"
|
83
|
+
},
|
84
|
+
pink: {
|
85
|
+
"pink" => "ffc0cb",
|
86
|
+
"lightpink" => "ffb6c1",
|
87
|
+
"hotpink" => "ff69b4",
|
88
|
+
"deeppink" => "ff1493",
|
89
|
+
"mediumvioletred" => "c71585",
|
90
|
+
"palevioletred" => "db7093"
|
91
|
+
},
|
92
|
+
brown: {
|
93
|
+
"cornsilk" => "fff8dc",
|
94
|
+
"blanchedalmond" => "ffebcd",
|
95
|
+
"bisque" => "ffe4c4",
|
96
|
+
"navajowhite" => "ffdead",
|
97
|
+
"wheat" => "f5deb3",
|
98
|
+
"burlywood" => "deb887",
|
99
|
+
"tan" => "d2b48c",
|
100
|
+
"rosybrown" => "bc8f8f",
|
101
|
+
"sandybrown" => "f4a460",
|
102
|
+
"goldenrod" => "daa520",
|
103
|
+
"darkgoldenrod" => "b8860b",
|
104
|
+
"peru" => "cd853f",
|
105
|
+
"chocolate" => "d2691e",
|
106
|
+
"saddlebrown" => "8b4513",
|
107
|
+
"sienna" => "a0522d",
|
108
|
+
"brown" => "a52a2a",
|
109
|
+
"maroon" => "800000"
|
110
|
+
},
|
111
|
+
white: {
|
112
|
+
"white" => "ffffff",
|
113
|
+
"snow" => "fffafa",
|
114
|
+
"honeydew" => "f0fff0",
|
115
|
+
"mintcream" => "f5fffa",
|
116
|
+
"azure" => "f0ffff",
|
117
|
+
"aliceblue" => "f0f8ff",
|
118
|
+
"ghostwhite" => "f8f8ff",
|
119
|
+
"whitesmoke" => "f5f5f5",
|
120
|
+
"seashell" => "fff5ee",
|
121
|
+
"beige" => "f5f5dc",
|
122
|
+
"oldlace" => "fdf5e6",
|
123
|
+
"floralwhite" => "fffaf0",
|
124
|
+
"ivory" => "fffff0",
|
125
|
+
"antiquewhite" => "faebd7",
|
126
|
+
"linen" => "faf0e6",
|
127
|
+
"lavenderblush" => "fff0f5",
|
128
|
+
"mistyrose" => "ffe4e1"
|
129
|
+
},
|
130
|
+
black: {
|
131
|
+
"gainsboro" => "dcdcdc",
|
132
|
+
"lightgray" => "d3d3d3",
|
133
|
+
"silver" => "c0c0c0",
|
134
|
+
"darkgray" => "a9a9a9",
|
135
|
+
"gray" => "808080",
|
136
|
+
"dimgray" => "696969",
|
137
|
+
"lightslategray" => "778899",
|
138
|
+
"slategray" => "708090",
|
139
|
+
"darkslategray" => "2f4f4f",
|
140
|
+
"black" => "000000"
|
141
|
+
},
|
142
|
+
gray: {
|
143
|
+
"gainsboro" => "dcdcdc",
|
144
|
+
"lightgray" => "d3d3d3",
|
145
|
+
"silver" => "c0c0c0",
|
146
|
+
"darkgray" => "a9a9a9",
|
147
|
+
"gray" => "808080",
|
148
|
+
"dimgray" => "696969",
|
149
|
+
"lightslategray" => "778899",
|
150
|
+
"slategray" => "708090",
|
151
|
+
"darkslategray" => "2f4f4f"
|
152
|
+
}
|
153
|
+
}.freeze
|
154
|
+
end
|
155
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "hex_color_generate/version"
|
4
|
+
require_relative "hex_color_generate/colors"
|
5
|
+
require_relative "hex_color_generate/class_methods"
|
6
|
+
|
7
|
+
# Generate random hex color
|
8
|
+
module HexColorGenerate
|
9
|
+
include HexColorGenerate::Colors
|
10
|
+
extend HexColorGenerate::ClassMethods
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hex_color_generate
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alef Ojeda de Oliveira
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-08-15 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: This gem generate hexadecimal color
|
14
|
+
email:
|
15
|
+
- alef.oliveira@dimensa.com.br
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".rspec"
|
21
|
+
- ".rubocop.yml"
|
22
|
+
- CHANGELOG.md
|
23
|
+
- LICENSE.txt
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- hex_color_generate.gemspec
|
27
|
+
- lib/hex_color_generate.rb
|
28
|
+
- lib/hex_color_generate/class_methods.rb
|
29
|
+
- lib/hex_color_generate/colors.rb
|
30
|
+
- lib/hex_color_generate/version.rb
|
31
|
+
- sig/hex_color_generate.rbs
|
32
|
+
homepage: https://github.com/nemuba/hex_color_generate
|
33
|
+
licenses:
|
34
|
+
- MIT
|
35
|
+
metadata:
|
36
|
+
homepage_uri: https://github.com/nemuba/hex_color_generate
|
37
|
+
source_code_uri: https://github.com/nemuba/hex_color_generate/tree/main
|
38
|
+
changelog_uri: https://github.com/nemuba/hex_color_generate/blob/main/CHANGELOG.md
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.7.1
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
requirements: []
|
54
|
+
rubygems_version: 3.4.14
|
55
|
+
signing_key:
|
56
|
+
specification_version: 4
|
57
|
+
summary: Generate hexadecimal color
|
58
|
+
test_files: []
|