ruby_color_contrast_checker 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7fd5330a1a1884e0a960e1eac58998c665f7b48a31325f365d01adf7547e73c1
4
- data.tar.gz: 9e5b4cac1f28ba6066903ed0d0ff4a3680f6845e9251a90eb95c435b928b35cf
3
+ metadata.gz: 40345e8b055888a53d71039c61513b0d6db1dd83acdf35657921bc9a303eed9f
4
+ data.tar.gz: 47be0542a7799e2b788596e395ac989fddee8035bb66561c61cea513a298c157
5
5
  SHA512:
6
- metadata.gz: 68c4a10255ec90887ea0d107c70c969dba2b7d2333d563273b0db94da5e52481c9c8a1c4064a76c45c8fda92727965ab94317696f30b4e5efdaca819990f0802
7
- data.tar.gz: 2af2e9180497133de98f1be80d09c9d36088b8636b83045b53d300d7fe6bf4f12640150cbe92ef6dd305a4c28d50d8965547031eb3d8fb3d7ce05ec208e578f1
6
+ metadata.gz: 5fb1724ffe3dab3f991e1a896c83282b5cb997be99faecd2eaa27ec814f38417d75bd1166113e50333e351eaa76544bc315762dbacefbe588c3d55047150878f
7
+ data.tar.gz: 1c340332128989b61e3a4460d052597664e8ec46389c5d259ee01c4e88e71435b5aa713a89dad184e49a36e5fae431937aa0786f6fd8619ae33fd990949e8cea
data/Gemfile CHANGED
@@ -4,3 +4,9 @@ source "https://rubygems.org"
4
4
 
5
5
  # Specify your gem's dependencies in ruby_color_contrast_checker.gemspec
6
6
  gemspec
7
+
8
+ gem "rake"
9
+ gem "rspec"
10
+ gem "standard"
11
+ gem "simplecov"
12
+ gem "simplecov-cobertura"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby_color_contrast_checker (0.1.0)
4
+ ruby_color_contrast_checker (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -52,6 +52,9 @@ GEM
52
52
  docile (~> 1.1)
53
53
  simplecov-html (~> 0.11)
54
54
  simplecov_json_formatter (~> 0.1)
55
+ simplecov-cobertura (2.1.0)
56
+ rexml
57
+ simplecov (~> 0.19)
55
58
  simplecov-html (0.12.3)
56
59
  simplecov_json_formatter (0.1.4)
57
60
  standard (1.28.4)
@@ -71,11 +74,12 @@ PLATFORMS
71
74
  x86_64-linux
72
75
 
73
76
  DEPENDENCIES
74
- rake (~> 13.0)
75
- rspec (~> 3.0)
77
+ rake
78
+ rspec
76
79
  ruby_color_contrast_checker!
77
- simplecov (~> 0.21.2)
78
- standard (~> 1.3)
80
+ simplecov
81
+ simplecov-cobertura
82
+ standard
79
83
 
80
84
  BUNDLED WITH
81
85
  2.4.7
data/README.md CHANGED
@@ -1,39 +1,137 @@
1
- # RubyColorContrastChecker
1
+ <div align="center">
2
+ <h1 align="center">Ruby Color Contrast Checker</h1>
3
+ <p align="center">CLI interface for checking WCAG2.0 Color Contrast Ratio in Ruby.</p>
4
+ </div>
5
+
6
+ <br />
7
+
8
+ <div align="center">
9
+ <a href="https://badge.fury.io/rb/ruby_color_contrast_checker">
10
+ <img alt="Gem Version" src="https://badge.fury.io/rb/ruby_color_contrast_checker.svg" />
11
+ </a>
12
+ &nbsp;
13
+ <a href="https://github.com/cheehwatang/ruby_color_contrast_checker/blob/main/LICENSE.txt">
14
+ <img alt="GitHub license" src="https://img.shields.io/github/license/cheehwatang/ruby_color_contrast_checker" />
15
+ </a>
16
+ &nbsp;
17
+ <a href="#">
18
+ <img alt="Tests Passing" src="https://github.com/cheehwatang/ruby_color_contrast_checker/workflows/Test/badge.svg" />
19
+ </a>
20
+ &nbsp;
21
+ <a href="#">
22
+ <img alt="Lint Passing" src="https://github.com/cheehwatang/ruby_color_contrast_checker/workflows/Lint/badge.svg" />
23
+ </a>
24
+ &nbsp;
25
+ <a href="#">
26
+ <img alt="Code Coverage Percentage" src="https://codecov.io/gh/cheehwatang/ruby_color_contrast_checker/branch/master/graph/badge.svg" />
27
+ </a>
28
+ &nbsp;
29
+ <a href="https://github.com/standardrb/standard">
30
+ <img alt="Ruby Code Style" src="https://img.shields.io/badge/code_style-standard-brightgreen.svg" />
31
+ </a>
32
+ &nbsp;
33
+ <a href="#">
34
+ <img alt="Repository Top Language" src="https://img.shields.io/github/languages/top/cheehwatang/ruby_color_contrast_checker" />
35
+ </a>
36
+ </div>
37
+
38
+ <br />
39
+
40
+ <hr />
41
+
42
+ <br />
43
+
44
+ Check if the 2 colors provided pass the AA and AAA Levels (including for Large Text and Icons), according to [WCAG 2.1 guidelines](https://www.w3.org/WAI/WCAG21/Understanding/contrast-minimum.html).
45
+
46
+ Further information can be found [here](https://webaim.org/articles/contrast/).
47
+
48
+ In summary:
49
+
50
+ - Level AA : Ratio > 4.5
51
+ - Level AA (Large) : Ratio > 3.0
52
+ - Level AAA : Ratio > 7.0
53
+ - Level AAA (Large) : Ratio > 4.5
54
+
55
+ Note:
56
+
57
+ Large is for regular text with 18pt or larger, or bold text with 14pt or larger.
58
+
59
+ Logo generally fall into the large category.
60
+
61
+ It is recommended to fulfill at least Level AA for your projects.
62
+
63
+ <br />
2
64
 
3
- TODO: Delete this and the text below, and describe your gem
65
+ ## Installation
4
66
 
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/ruby_color_contrast_checker`. To experiment with that code, run `bin/console` for an interactive prompt.
67
+ Install the gem:
6
68
 
7
- ## Installation
69
+ ```console
70
+ $ gem install ruby_color_contrast_checker
71
+ ```
8
72
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
73
+ <br />
10
74
 
11
- Install the gem and add to the application's Gemfile by executing:
75
+ ## Usage
12
76
 
13
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
77
+ Run the `contrast_checker` executable:
14
78
 
15
- If bundler is not being used to manage dependencies, install the gem by executing:
79
+ ```shell
80
+ $ contrast_checker
16
81
 
17
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
82
+ ------------------------------------
83
+ | Welcome to Color Contrast Checker |
84
+ ------------------------------------
85
+ \ ^__^
86
+ \ (oo)_______
87
+ (__)\ )\/\
88
+ ||----w |
89
+ || ||
18
90
 
19
- ## Usage
91
+ Enter the first hex color string:
92
+ > #000000
93
+ Enter the second hex color string:
94
+ > #FFFFFF
95
+
96
+ Contrast Ratio : 21
97
+
98
+ Level AA : PASS
99
+ Level AA (Large) : PASS
100
+ Level AAA : PASS
101
+ Level AAA (Large) : PASS
102
+ ```
103
+
104
+ ![Color Contrast Checker CLI](./assets/color_contrast_checker_cli.png)
20
105
 
21
- TODO: Write usage instructions here
106
+ <br />
22
107
 
23
108
  ## Development
24
109
 
25
110
  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.
26
111
 
27
- 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).
112
+ To install this gem onto your local machine, run `bundle exec rake install`.
113
+
114
+ <br />
28
115
 
29
116
  ## Contributing
30
117
 
31
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ruby_color_contrast_checker. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/ruby_color_contrast_checker/blob/master/CODE_OF_CONDUCT.md).
118
+ Bug reports and pull requests are welcome on GitHub at https://github.com/cheehwatang/ruby_color_contrast_checker. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/cheehwatang/ruby_color_contrast_checker/blob/master/CODE_OF_CONDUCT.md).
119
+
120
+ <br />
32
121
 
33
122
  ## License
34
123
 
35
124
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
36
125
 
126
+ <br />
127
+
37
128
  ## Code of Conduct
38
129
 
39
- Everyone interacting in the RubyColorContrastChecker project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/ruby_color_contrast_checker/blob/master/CODE_OF_CONDUCT.md).
130
+ Everyone interacting in the Ruby Color Contrast Checker project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/cheehwatang/ruby_color_contrast_checker/blob/master/CODE_OF_CONDUCT.md).
131
+
132
+ <br />
133
+
134
+ ## 🌟 Special Thanks
135
+
136
+ - [WebAIM Contrast Checker API](https://webaim.org/resources/contrastchecker/) for the contrast checker API.
137
+ - [Richard Bates](https://github.com/richo225) for the [blog post](https://richardbates.dev/blog/2023-05-05) on releasing a gem.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyColorContrastChecker
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
@@ -34,35 +34,78 @@ module RubyColorContrastChecker
34
34
  gets.chomp
35
35
  end
36
36
 
37
+ def red(string)
38
+ "\e[31m#{string}\e[0m"
39
+ end
40
+
41
+ def green(string)
42
+ "\e[32m#{string}\e[0m"
43
+ end
44
+
45
+ def colorize_float(float_string)
46
+ return red(float_string) if Float(float_string) < 4.5
47
+
48
+ green(float_string)
49
+ end
50
+
51
+ def colorize_status(status_string)
52
+ status_string = status_string.upcase
53
+
54
+ return red(status_string) if status_string == "FAIL"
55
+
56
+ green(status_string)
57
+ end
58
+
37
59
  def print_data(data)
38
60
  output = <<~MLS
39
- Contrast Ratio : #{data["ratio"]}
61
+ \e[36mContrast Ratio\e[0m : #{colorize_float(data["ratio"])}
40
62
 
41
- Level AA : #{data["AA"].upcase}
42
- Level AA (Large) : #{data["AALarge"].upcase}
43
- Level AAA : #{data["AAA"].upcase}
44
- Level AAA (Large) : #{data["AAALarge"].upcase}
63
+ \e[36mLevel AA\e[0m : #{colorize_status(data["AA"])}
64
+ \e[36mLevel AA (Large)\e[0m : #{colorize_status(data["AALarge"])}
65
+ \e[36mLevel AAA\e[0m : #{colorize_status(data["AAA"])}
66
+ \e[36mLevel AAA (Large)\e[0m : #{colorize_status(data["AAALarge"])}
45
67
  MLS
46
68
 
47
69
  puts output
48
70
  end
49
71
 
72
+ def print_welcome_message
73
+ welcome_message = <<~MLS
74
+ \e[36m ------------------------------------ \e[0m
75
+ \e[36m | Welcome to Color Contrast Checker | \e[0m
76
+ \e[36m ------------------------------------ \e[0m
77
+ \\ ^__^
78
+ \\ (oo)_______
79
+ (__)\\ )\\/\\
80
+ ||----w |
81
+ || ||
82
+ MLS
83
+
84
+ puts welcome_message
85
+ end
86
+
87
+ def print_error_message
88
+ puts "\e[31mThe Hex color code is invalid.\e[0m"
89
+ end
90
+
50
91
  def run
92
+ print_welcome_message
93
+
51
94
  loop do
52
95
  puts
53
- first = prompt_input("Enter the first hex color string: \n> #")
54
- second = prompt_input("Enter the second hex color string: \n> #")
96
+ first = prompt_input("\e[36mEnter the first hex color string:\e[0m \n\e[30m> #\e[0m")
97
+ second = prompt_input("\e[36mEnter the second hex color string:\e[0m \n\e[30m> #\e[0m")
55
98
  puts
56
99
 
57
100
  if !valid_hex?(first) || !valid_hex?(second)
58
- puts "The Hex color code is invalid."
101
+ print_error_message
59
102
  else
60
103
  data = fetch_data(first, second)
61
104
  print_data(data)
62
105
  end
63
106
 
64
107
  puts
65
- input = prompt_input("Continue? (yes / no) ")
108
+ input = prompt_input("\e[33mContinue?\e[0m (\e[32myes\e[0m / \e[31mno\e[0m) ")
66
109
  break if input.downcase == "no"
67
110
  end
68
111
  end
@@ -29,9 +29,4 @@ Gem::Specification.new do |spec|
29
29
  end
30
30
  spec.executables = ["contrast_checker"]
31
31
  spec.require_paths = ["lib"]
32
-
33
- spec.add_development_dependency "rake", "~> 13.0"
34
- spec.add_development_dependency "rspec", "~> 3.0"
35
- spec.add_development_dependency "standard", "~> 1.3"
36
- spec.add_development_dependency "simplecov", "~> 0.21.2"
37
32
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_color_contrast_checker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chee Hwa Tang
@@ -9,63 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2023-05-30 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rake
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '13.0'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '13.0'
27
- - !ruby/object:Gem::Dependency
28
- name: rspec
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '3.0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '3.0'
41
- - !ruby/object:Gem::Dependency
42
- name: standard
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '1.3'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '1.3'
55
- - !ruby/object:Gem::Dependency
56
- name: simplecov
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: 0.21.2
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: 0.21.2
12
+ dependencies: []
69
13
  description: 'CLI interface for WCAG Color Contrast Checking in Ruby '
70
14
  email:
71
15
  - cheehwa.tang@gmail.com
@@ -83,6 +27,7 @@ files:
83
27
  - LICENSE.txt
84
28
  - README.md
85
29
  - Rakefile
30
+ - assets/color_contrast_checker_cli.png
86
31
  - bin/contrast_checker
87
32
  - lib/ruby_color_contrast_checker.rb
88
33
  - lib/ruby_color_contrast_checker/version.rb