color_space_converter 0.1.0

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: 20cb71e19d5243302559a2388d69a354d8decf4bf3ce06627e07542b6347eba5
4
+ data.tar.gz: cb64045e462e2f85663da9d8fe0bd4c6c78f040db1e442b42e1465806da5a4cc
5
+ SHA512:
6
+ metadata.gz: 33decd7be1dd6331ac4d397315f500ca714dc447d5729774db836469efa46cb9e08e27eabf3833344204b275a93e0c4f3fb05b9a433e1aad41092d8139265e1f
7
+ data.tar.gz: c2bb4e71430069e64ec5f1fbaa295a746d8bd98ce77dfbee8d214e7dc743a1dde3e4d4a71b92fc7fad2b38025fd0518fb525035aa709b87a29c4aecfab474fd3
data/.coveralls.yml ADDED
@@ -0,0 +1,2 @@
1
+ service_name: travis-pro
2
+ repo_token: Q9uPrpfO6hchQBMKBK2cbg5wx2aVArmkv
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1 @@
1
+ inherit_from: .rubocop_todo.yml
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,208 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2018-12-26 18:09:34 +0900 using RuboCop version 0.61.1.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ # Cop supports --auto-correct.
11
+ # Configuration parameters: TreatCommentsAsGroupSeparators, Include.
12
+ # Include: **/*.gemspec
13
+ Gemspec/OrderedDependencies:
14
+ Exclude:
15
+ - 'color_space_converter.gemspec'
16
+
17
+ # Offense count: 2
18
+ # Cop supports --auto-correct.
19
+ Layout/EmptyLines:
20
+ Exclude:
21
+ - 'spec/spec_helper.rb'
22
+
23
+ # Offense count: 2
24
+ # Cop supports --auto-correct.
25
+ # Configuration parameters: AllowForAlignment, ForceEqualSignAlignment.
26
+ Layout/ExtraSpacing:
27
+ Exclude:
28
+ - 'color_space_converter.gemspec'
29
+ - 'lib/color_space_converter/compute.rb'
30
+
31
+ # Offense count: 1
32
+ # Cop supports --auto-correct.
33
+ # Configuration parameters: EnforcedStyle, IndentationWidth.
34
+ # SupportedStyles: consistent, consistent_relative_to_receiver, special_for_inner_method_call, special_for_inner_method_call_in_parentheses
35
+ Layout/FirstParameterIndentation:
36
+ Exclude:
37
+ - 'spec/color_space_converter/const_spec.rb'
38
+
39
+ # Offense count: 1
40
+ # Cop supports --auto-correct.
41
+ Layout/LeadingBlankLines:
42
+ Exclude:
43
+ - 'color_space_converter.gemspec'
44
+
45
+ # Offense count: 64
46
+ # Cop supports --auto-correct.
47
+ # Configuration parameters: AllowForAlignment.
48
+ Layout/SpaceAroundOperators:
49
+ Exclude:
50
+ - 'color_space_converter.gemspec'
51
+ - 'lib/color_space_converter/compute.rb'
52
+
53
+ # Offense count: 14
54
+ # Cop supports --auto-correct.
55
+ # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
56
+ # SupportedStyles: space, no_space
57
+ # SupportedStylesForEmptyBraces: space, no_space
58
+ Layout/SpaceInsideBlockBraces:
59
+ Exclude:
60
+ - 'Gemfile'
61
+ - 'spec/color_space_converter/color_space_spec.rb'
62
+ - 'spec/color_space_converter/compute_spec.rb'
63
+
64
+ # Offense count: 5
65
+ # Cop supports --auto-correct.
66
+ # Configuration parameters: EnforcedStyle.
67
+ # SupportedStyles: final_newline, final_blank_line
68
+ Layout/TrailingBlankLines:
69
+ Exclude:
70
+ - 'lib/color_space_converter/color_space.rb'
71
+ - 'lib/color_space_converter/compute.rb'
72
+ - 'lib/color_space_converter/const.rb'
73
+ - 'spec/color_space_converter/color_space_spec.rb'
74
+ - 'spec/color_space_converter/const_spec.rb'
75
+
76
+ # Offense count: 6
77
+ Lint/ParenthesesAsGroupedExpression:
78
+ Exclude:
79
+ - 'spec/color_space_converter/color_space_spec.rb'
80
+
81
+ # Offense count: 4
82
+ Metrics/AbcSize:
83
+ Max: 37
84
+
85
+ # Offense count: 4
86
+ # Configuration parameters: CountComments, ExcludedMethods.
87
+ # ExcludedMethods: refine
88
+ Metrics/BlockLength:
89
+ Max: 37
90
+
91
+ # Offense count: 5
92
+ # Configuration parameters: CountComments, ExcludedMethods.
93
+ Metrics/MethodLength:
94
+ Max: 28
95
+
96
+ # Offense count: 1
97
+ # Configuration parameters: CountComments.
98
+ Metrics/ModuleLength:
99
+ Max: 106
100
+
101
+ # Offense count: 4
102
+ # Configuration parameters: CountKeywordArgs.
103
+ Metrics/ParameterLists:
104
+ Max: 6
105
+
106
+ # Offense count: 1
107
+ Metrics/PerceivedComplexity:
108
+ Max: 9
109
+
110
+ # Offense count: 27
111
+ # Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
112
+ # AllowedNames: io, id, to, by, on, in, at, ip, db
113
+ Naming/UncommunicativeMethodParamName:
114
+ Exclude:
115
+ - 'lib/color_space_converter.rb'
116
+ - 'lib/color_space_converter/color_space.rb'
117
+ - 'lib/color_space_converter/compute.rb'
118
+
119
+ # Offense count: 7
120
+ # Cop supports --auto-correct.
121
+ # Configuration parameters: EnforcedStyle, SingleLineConditionsOnly, IncludeTernaryExpressions.
122
+ # SupportedStyles: assign_to_condition, assign_inside_condition
123
+ Style/ConditionalAssignment:
124
+ Exclude:
125
+ - 'lib/color_space_converter/compute.rb'
126
+
127
+ # Offense count: 3
128
+ Style/Documentation:
129
+ Exclude:
130
+ - 'spec/**/*'
131
+ - 'test/**/*'
132
+ - 'lib/color_space_converter.rb'
133
+ - 'lib/color_space_converter/color_space.rb'
134
+ - 'lib/color_space_converter/compute.rb'
135
+
136
+ # Offense count: 2
137
+ # Cop supports --auto-correct.
138
+ Style/ExpandPathArguments:
139
+ Exclude:
140
+ - 'color_space_converter.gemspec'
141
+
142
+ # Offense count: 1
143
+ # Cop supports --auto-correct.
144
+ # Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
145
+ # SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
146
+ Style/HashSyntax:
147
+ Exclude:
148
+ - 'Rakefile'
149
+
150
+ # Offense count: 2
151
+ # Cop supports --auto-correct.
152
+ Style/MutableConstant:
153
+ Exclude:
154
+ - 'lib/color_space_converter/const.rb'
155
+ - 'lib/color_space_converter/version.rb'
156
+
157
+ # Offense count: 2
158
+ # Cop supports --auto-correct.
159
+ # Configuration parameters: PreferredDelimiters.
160
+ Style/PercentLiteralDelimiters:
161
+ Exclude:
162
+ - 'color_space_converter.gemspec'
163
+
164
+ # Offense count: 6
165
+ # Cop supports --auto-correct.
166
+ Style/RedundantParentheses:
167
+ Exclude:
168
+ - 'spec/color_space_converter/color_space_spec.rb'
169
+
170
+ # Offense count: 1
171
+ # Cop supports --auto-correct.
172
+ # Configuration parameters: AllowMultipleReturnValues.
173
+ Style/RedundantReturn:
174
+ Exclude:
175
+ - 'lib/color_space_converter.rb'
176
+
177
+ # Offense count: 3
178
+ # Cop supports --auto-correct.
179
+ Style/SelfAssignment:
180
+ Exclude:
181
+ - 'lib/color_space_converter/compute.rb'
182
+
183
+ # Offense count: 40
184
+ # Cop supports --auto-correct.
185
+ # Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
186
+ # SupportedStyles: single_quotes, double_quotes
187
+ Style/StringLiterals:
188
+ Exclude:
189
+ - 'Gemfile'
190
+ - 'Rakefile'
191
+ - 'bin/console'
192
+ - 'color_space_converter.gemspec'
193
+ - 'lib/color_space_converter.rb'
194
+ - 'lib/color_space_converter/version.rb'
195
+ - 'spec/color_space_converter_spec.rb'
196
+ - 'spec/spec_helper.rb'
197
+
198
+ # Offense count: 2
199
+ # Cop supports --auto-correct.
200
+ Style/UnneededPercentQ:
201
+ Exclude:
202
+ - 'color_space_converter.gemspec'
203
+
204
+ # Offense count: 18
205
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
206
+ # URISchemes: http, https
207
+ Metrics/LineLength:
208
+ Max: 141
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.3
7
+ before_install:
8
+ - gem install bundler -v 1.17
9
+ - gem install rubocop
10
+ script:
11
+ - rubocop --fail-level=W
12
+ - bundle exec rspec
data/CHANGELOG.md ADDED
File without changes
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at mikamimikami60@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in color_space_converter.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,71 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ color_space_converter (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.0)
10
+ coveralls (0.8.22)
11
+ json (>= 1.8, < 3)
12
+ simplecov (~> 0.16.1)
13
+ term-ansicolor (~> 1.3)
14
+ thor (~> 0.19.4)
15
+ tins (~> 1.6)
16
+ diff-lcs (1.3)
17
+ docile (1.3.1)
18
+ jaro_winkler (1.5.1)
19
+ json (2.1.0)
20
+ parallel (1.12.1)
21
+ parser (2.5.3.0)
22
+ ast (~> 2.4.0)
23
+ powerpack (0.1.2)
24
+ rainbow (3.0.0)
25
+ rake (10.5.0)
26
+ rspec (3.8.0)
27
+ rspec-core (~> 3.8.0)
28
+ rspec-expectations (~> 3.8.0)
29
+ rspec-mocks (~> 3.8.0)
30
+ rspec-core (3.8.0)
31
+ rspec-support (~> 3.8.0)
32
+ rspec-expectations (3.8.2)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.8.0)
35
+ rspec-mocks (3.8.0)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.8.0)
38
+ rspec-support (3.8.0)
39
+ rubocop (0.61.1)
40
+ jaro_winkler (~> 1.5.1)
41
+ parallel (~> 1.10)
42
+ parser (>= 2.5, != 2.5.1.1)
43
+ powerpack (~> 0.1)
44
+ rainbow (>= 2.2.2, < 4.0)
45
+ ruby-progressbar (~> 1.7)
46
+ unicode-display_width (~> 1.4.0)
47
+ ruby-progressbar (1.10.0)
48
+ simplecov (0.16.1)
49
+ docile (~> 1.1)
50
+ json (>= 1.8, < 3)
51
+ simplecov-html (~> 0.10.0)
52
+ simplecov-html (0.10.2)
53
+ term-ansicolor (1.7.0)
54
+ tins (~> 1.0)
55
+ thor (0.19.4)
56
+ tins (1.20.2)
57
+ unicode-display_width (1.4.1)
58
+
59
+ PLATFORMS
60
+ ruby
61
+
62
+ DEPENDENCIES
63
+ bundler (~> 1.17)
64
+ color_space_converter!
65
+ coveralls
66
+ rake (~> 10.0)
67
+ rspec (~> 3.0)
68
+ rubocop
69
+
70
+ BUNDLED WITH
71
+ 1.17.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 TaigaMikami
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,77 @@
1
+ [![Build Status](https://travis-ci.org/TaigaMikami/color_space_converter.svg?branch=master)](https://travis-ci.org/TaigaMikami/color_space_converter)
2
+ [![Coverage Status](https://coveralls.io/repos/github/TaigaMikami/color_space_converter/badge.svg?branch=master)](https://coveralls.io/github/TaigaMikami/color_space_converter?branch=master)
3
+
4
+ # ColorSpaceConverter
5
+
6
+ Welcome to ColorSpaceConverter gem!
7
+ It is a gem for easy conversion of color space such as rgb, xyz, lab.
8
+
9
+ ## Corresponding color space
10
+ - rgb(hex)
11
+ - rgb
12
+ - xyz
13
+ - lab
14
+
15
+ ## Installation
16
+
17
+ Add this line to your application's Gemfile:
18
+
19
+ ```ruby
20
+ gem 'color_space_converter'
21
+ ```
22
+
23
+ And then execute:
24
+
25
+ $ bundle
26
+
27
+ Or install it yourself as:
28
+
29
+ $ gem install color_space_converter
30
+
31
+ ## Usage
32
+
33
+ ### Instantiation
34
+
35
+ ```ruby
36
+ require 'color_space_converter'
37
+
38
+ obj = ColorSpaceConverter.new
39
+
40
+ # Otherwise
41
+ # ColorSpaceConverter.new(color_space, element1(ex: r), element2(ex: g), element3(ex: b))
42
+ obj = ColorSpaceConverter.new('rgb', 128, 128, 128)
43
+
44
+ ```
45
+
46
+ ### Calculation
47
+ ```ruby
48
+ # to rgb
49
+ obj.calc_rgb
50
+
51
+ # to xyz
52
+ obj.calc_xyz
53
+
54
+ # to lab
55
+ obj.calc_lab
56
+
57
+ ```
58
+ ## Development
59
+
60
+ 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.
61
+
62
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
63
+
64
+ ## Contributing
65
+
66
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/color_space_converter. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
67
+
68
+ ## License
69
+
70
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
71
+
72
+ ## Code of Conduct
73
+
74
+ Everyone interacting in the ColorSpaceConverter project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/color_space_converter/blob/master/CODE_OF_CONDUCT.md).
75
+
76
+ ## Author
77
+ [TaigaMikami](https://github.com/TaigaMikami)
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "color_space_converter"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,44 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "color_space_converter/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "color_space_converter"
8
+ spec.version = ColorSpaceConverter::VERSION
9
+ spec.authors = ["TaigaMikami"]
10
+ spec.email = ["mikamimikami60@gmail.com"]
11
+
12
+ spec.summary = %q{This gem is for converting color space.}
13
+ spec.description = %q{This gem is for converting color space.}
14
+ spec.homepage = "https://github.com/TaigaMikami/color_space_converter"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ # spec.metadata["allowed_push_host"] = "https://github.com/TaigaMikami/color_space_converter"
21
+
22
+ spec.metadata["homepage_uri"] = spec.homepage
23
+ spec.metadata["source_code_uri"] = "https://github.com/TaigaMikami/color_space_converter"
24
+ spec.metadata["changelog_uri"] = "https://github.com/TaigaMikami/color_space_converter/CHANGELOG.md"
25
+ else
26
+ raise "RubyGems 2.0 or newer is required to protect against " \
27
+ "public gem pushes."
28
+ end
29
+
30
+ # Specify which files should be added to the gem when it is released.
31
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
32
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
33
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
34
+ end
35
+ spec.bindir = "exe"
36
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
+ spec.require_paths = ["lib"]
38
+
39
+ spec.add_development_dependency "bundler", "~> 1.17"
40
+ spec.add_development_dependency "rake", "~> 10.0"
41
+ spec.add_development_dependency "rspec", "~> 3.0"
42
+ spec.add_development_dependency "coveralls"
43
+ spec.add_development_dependency "rubocop"
44
+ end
@@ -0,0 +1,51 @@
1
+ require 'color_space_converter/compute'
2
+ require 'color_space_converter/const'
3
+
4
+ module ColorSpaceConverter
5
+ class ColorSpace
6
+ attr_reader :rgb, :xyz, :lab, :hex
7
+
8
+ include ColorSpaceConverter::Compute
9
+
10
+ def initialize(space, e1, e2, e3)
11
+ @init_space = space
12
+ if space == 'rgb'
13
+ @rgb = [e1, e2, e3]
14
+ elsif space == 'xyz'
15
+ @xyz = [e1, e2, e3]
16
+ elsif space == 'lab'
17
+ @lab = [e1, e2, e3]
18
+ else
19
+ @init_space = ''
20
+ puts ColorSpaceConverter::Const::ERROR_USAGE
21
+ end
22
+ end
23
+
24
+ def calc_rgb(x_n: 100, y_n: 100, z_n: 100)
25
+ if @xyz
26
+ @rgb = xyz2rgb(@xyz[0], @xyz[1], @rgb[2])
27
+ elsif @lab
28
+ @rgb = lab2rgb(@lab[0], @lab[1], @lab[2], x_n: x_n, y_n: y_n, z_n: z_n)
29
+ end
30
+ @rgb
31
+ end
32
+
33
+ def calc_xyz(x_n: 100, y_n: 100, z_n: 100)
34
+ if @rgb
35
+ @xyz = rgb2xyz(@rgb[0], @rgb[1], @rgb[2])
36
+ elsif @lab
37
+ @xyz = lab2xyz(@lab[0], @lab[1], @lab[2], x_n: x_n, y_n: y_n, z_n: z_n)
38
+ end
39
+ @xyz
40
+ end
41
+
42
+ def calc_lab(x_n: 100, y_n: 100, z_n: 100)
43
+ if @rgb
44
+ @lab = rgb2lab(@rgb[0], @rgb[1], @rgb[2], x_n: x_n, y_n: y_n, z_n: z_n)
45
+ elsif @xyz
46
+ @lab = xyz2lab(@xyz[0], @xyz[1], @xyz[2], x_n: x_n, y_n: y_n, z_n: z_n)
47
+ end
48
+ @lab
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,127 @@
1
+ module ColorSpaceConverter
2
+ module Compute
3
+ module_function
4
+
5
+ def rgb2hex(r, g, b)
6
+ hex = '#'
7
+ [r, g, b].each do |n|
8
+ hex += n.to_s(16).rjust(2, '0')
9
+ end
10
+ hex
11
+ end
12
+
13
+ def hex2rgb(hex)
14
+ r = hex[1..2]
15
+ g = hex[3..4]
16
+ b = hex[5..6]
17
+ rgb = []
18
+ [r, g, b].each do |s|
19
+ rgb << s.hex
20
+ end
21
+ rgb
22
+ end
23
+
24
+ def rgb2xyz(r, g, b)
25
+ s_rgb = []
26
+ [r, g, b].each do |n|
27
+ n = n.to_f / 255
28
+ if n <= 0.0405
29
+ s_n = n / 12.92
30
+ else
31
+ s_n = ((n+0.055) / 1.055) ** 2.4
32
+ end
33
+ s_rgb << s_n
34
+ end
35
+
36
+ x = s_rgb[0]*0.4124 + s_rgb[1]*0.3576 + s_rgb[2]*0.1805
37
+ y = s_rgb[0]*0.2126 + s_rgb[1]*0.7152 + s_rgb[2]*0.0722
38
+ z = s_rgb[0]*0.0193+ s_rgb[1]*0.1192+ s_rgb[2]*0.9505
39
+ [x*100, y*100, z*100]
40
+ end
41
+
42
+ def xyz2rgb(x, y, z)
43
+ x = x / 100
44
+ y = y / 100
45
+ z = z / 100
46
+
47
+ s_r = 3.2406*x-1.5372*y-0.4986*z
48
+ s_g = -0.9689*x+1.8758*y+0.0415*z
49
+ s_b = 0.0557*x-0.2040*y+1.0570*z
50
+
51
+ rgb = []
52
+ [s_r, s_g, s_b].each do |s_n|
53
+ if s_n <= 0.0031308
54
+ n = s_n * 12.92
55
+ else
56
+ n = 1.055 * (s_n**(1.0/2.4)) - 0.055
57
+ end
58
+ rgb << (n*255).to_i
59
+ end
60
+ rgb
61
+ end
62
+
63
+ def xyz2lab(x, y, z, x_n: 100.0, y_n: 100.0, z_n: 100.0)
64
+ xyz_n = [x_n, y_n, z_n]
65
+ f_xyz = []
66
+ [x, y, z].each_with_index do |n, i|
67
+ if n/xyz_n[i] < 0.008856
68
+ f = (903.3*n/xyz_n[i]+16)/116
69
+ else
70
+ f = (n/xyz_n[i])**(1.0/3.0)
71
+ end
72
+ f_xyz << f
73
+ end
74
+ l = 116*f_xyz[1] - 16
75
+ a = 500*(f_xyz[0]-f_xyz[1])
76
+ b = 200*(f_xyz[1]-f_xyz[2])
77
+ [l, a, b]
78
+ end
79
+
80
+ def lab2xyz(l, a, b, x_n: 100.0, y_n: 100.0, z_n: 100.0)
81
+ xyz_n = [x_n, y_n, z_n]
82
+ xyz = []
83
+
84
+ if l > 903.3*0.008856
85
+ y = ((l+16)/116)**3
86
+ else
87
+ y = l/903.3
88
+ end
89
+
90
+ if y > 0.008856
91
+ fy = (l+16)/116
92
+ else
93
+ fy = (903.3*y+16)/116
94
+ end
95
+
96
+ fx = a/500 + fy
97
+ fz = fy - b/200
98
+
99
+ if fz**3 > 0.008856
100
+ x = fx**3
101
+ else
102
+ x = (116*fx-16)/903.3
103
+ end
104
+
105
+ if fz**3 > 0.008856
106
+ z = fz**3
107
+ else
108
+ z = (116*fz-16)/903.3
109
+ end
110
+
111
+ [x, y, z].each_with_index do |n, i|
112
+ xyz << xyz_n[i] * n
113
+ end
114
+ xyz
115
+ end
116
+
117
+ def rgb2lab(r, g, b, x_n: 100.0, y_n: 100.0, z_n: 100.0)
118
+ x, y, z = rgb2xyz(r, g, b)
119
+ xyz2lab(x, y, z, x_n: x_n, y_n: y_n, z_n: z_n)
120
+ end
121
+
122
+ def lab2rgb(l, a, b, x_n: 100.0, y_n: 100.0, z_n: 100.0)
123
+ x, y, z = lab2xyz(l, a, b, x_n: x_n, y_n: y_n, z_n: z_n)
124
+ xyz2rgb(x, y, z)
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,5 @@
1
+ module ColorSpaceConverter
2
+ module Const
3
+ ERROR_USAGE = '[USAGE] `ColorSpaceConverter.new(color_space, e1(r), e2(g), e3(b)`'
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module ColorSpaceConverter
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,15 @@
1
+ require "color_space_converter/version"
2
+ require "color_space_converter/color_space"
3
+ require "color_space_converter/compute"
4
+
5
+ module ColorSpaceConverter
6
+ class Error < StandardError; end
7
+
8
+ def self.new(space = ARGV[0], e1 = ARGV[1], e2 = ARGV[2], e3 = ARGV[3])
9
+ space ||= 'rgb'
10
+ e1 ||= 0
11
+ e2 ||= 0
12
+ e3 ||= 0
13
+ return ColorSpaceConverter::ColorSpace.new(space, e1, e2, e3)
14
+ end
15
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: color_space_converter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - TaigaMikami
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-12-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: coveralls
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: This gem is for converting color space.
84
+ email:
85
+ - mikamimikami60@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".coveralls.yml"
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".rubocop.yml"
94
+ - ".rubocop_todo.yml"
95
+ - ".travis.yml"
96
+ - CHANGELOG.md
97
+ - CODE_OF_CONDUCT.md
98
+ - Gemfile
99
+ - Gemfile.lock
100
+ - LICENSE.txt
101
+ - README.md
102
+ - Rakefile
103
+ - bin/console
104
+ - bin/setup
105
+ - color_space_converter.gemspec
106
+ - lib/color_space_converter.rb
107
+ - lib/color_space_converter/color_space.rb
108
+ - lib/color_space_converter/compute.rb
109
+ - lib/color_space_converter/const.rb
110
+ - lib/color_space_converter/version.rb
111
+ homepage: https://github.com/TaigaMikami/color_space_converter
112
+ licenses:
113
+ - MIT
114
+ metadata:
115
+ homepage_uri: https://github.com/TaigaMikami/color_space_converter
116
+ source_code_uri: https://github.com/TaigaMikami/color_space_converter
117
+ changelog_uri: https://github.com/TaigaMikami/color_space_converter/CHANGELOG.md
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 2.7.7
135
+ signing_key:
136
+ specification_version: 4
137
+ summary: This gem is for converting color space.
138
+ test_files: []