wcag_color_contrast 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 409a9a32d764aa58736e52425280daac433d59ef
4
+ data.tar.gz: edc08eb2b5ecc5c7cb6ec6a0ad9e9b13526939ab
5
+ SHA512:
6
+ metadata.gz: 50481e57f9f92481ae24e0a147cbca0227d022e129f8bca06b7474b0aac23600864093a6899db245155c25c0b041e010b7b60cbd3eeeab69e07f8eb3eb3d470d
7
+ data.tar.gz: 885749d694361beed564bb2c3c22b2120e77fcc6c8f49142dc924488910ca28794d35c3b058b83851bed1045c794be4da5b28a8d66154db9128e49d8c6fd9e63
data/README.md CHANGED
@@ -26,14 +26,21 @@ $ gem install wcag_color_contrast
26
26
 
27
27
  ## Usage
28
28
 
29
- Pass 2 rgb colors are strings (3 or 6 characters, case insensitive):
29
+ With 2 hex colors as strings (3 or 6 characters, case insensitive, no leading pound/hash sign):
30
30
 
31
31
  ```ruby
32
32
  require 'wcag_color_contrast'
33
- WCAGColorContrast.new.ratio('999', 'ffffff')
33
+ WCAGColorContrast.ratio('999', 'ffffff')
34
34
  #=> 2.849027755287037
35
35
  ```
36
36
 
37
+ Can also calculate the relative luminance of a color
38
+
39
+ ```ruby
40
+ WCAGColorContrast.relative_luminance('008800')
41
+ #=> 0.17608318886144392
42
+ ```
43
+
37
44
  ## Contributing
38
45
 
39
46
  1. Fork it
@@ -41,3 +48,7 @@ WCAGColorContrast.new.ratio('999', 'ffffff')
41
48
  3. Commit your changes (`git commit -am 'Add some feature'`)
42
49
  4. Push to the branch (`git push origin my-new-feature`)
43
50
  5. Create new Pull Request
51
+
52
+
53
+ [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/mkdynamic/wcag_color_contrast/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
54
+
@@ -3,11 +3,15 @@ require "wcag_color_contrast/version"
3
3
  module WCAGColorContrast
4
4
  class InvalidColorError < StandardError; end
5
5
 
6
- # Helper method for WCAGColorContrast#new#ratio.
6
+ # Helper method for WCAGColorContrast::Ratio.new#ratio.
7
7
  def self.ratio(*args)
8
8
  Ratio.new.ratio(*args)
9
9
  end
10
10
 
11
+ def self.relative_luminance(rgb)
12
+ Ratio.new.relative_luminance(rgb)
13
+ end
14
+
11
15
  class Ratio
12
16
  # Calculate contast ratio beetween RGB1 and RGB2.
13
17
  def ratio(rgb1, rgb2)
@@ -23,6 +27,14 @@ module WCAGColorContrast
23
27
  l1 > l2 ? (l1 + 0.05) / (l2 + 0.05) : (l2 + 0.05) / (l1 + 0.05)
24
28
  end
25
29
 
30
+ # Calculate the relative luminance for an rgb color
31
+ def relative_luminance(rgb)
32
+ raise InvalidColorError, rgb unless valid_rgb?(rgb)
33
+
34
+ srgb = rgb_to_srgba(rgb)
35
+ srgb_lightness(srgb)
36
+ end
37
+
26
38
  private
27
39
 
28
40
  # Convert RGB color to sRGB.
@@ -1,3 +1,3 @@
1
1
  module WCAGColorContrast
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -8,4 +8,9 @@ class WCAGColorContrastTest < MiniTest::Unit::TestCase
8
8
  assert_in_delta 1.425, WCAGColorContrast.ratio('d8d8d8', 'fff')
9
9
  assert_in_delta 1.956, WCAGColorContrast.ratio('eee', 'AAABBB')
10
10
  end
11
+
12
+ def test_relative_luminance
13
+ assert_equal 1, WCAGColorContrast.relative_luminance('ffffff')
14
+ assert_in_delta 0.176, WCAGColorContrast.relative_luminance('008800')
15
+ end
11
16
  end
metadata CHANGED
@@ -1,62 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wcag_color_contrast
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ version: 0.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Mark Dodwell
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-05-30 00:00:00.000000000 Z
11
+ date: 2017-11-13 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bundler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
19
  version: '1.3'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
26
  version: '1.3'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: minitest
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - ">="
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - ">="
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  description:
@@ -66,7 +59,7 @@ executables: []
66
59
  extensions: []
67
60
  extra_rdoc_files: []
68
61
  files:
69
- - .gitignore
62
+ - ".gitignore"
70
63
  - Gemfile
71
64
  - LICENSE.txt
72
65
  - README.md
@@ -78,33 +71,26 @@ files:
78
71
  homepage: https://github.com/mkdynamic/wcag_color_contrast
79
72
  licenses:
80
73
  - MIT
74
+ metadata: {}
81
75
  post_install_message:
82
76
  rdoc_options: []
83
77
  require_paths:
84
78
  - lib
85
79
  required_ruby_version: !ruby/object:Gem::Requirement
86
- none: false
87
80
  requirements:
88
- - - ! '>='
81
+ - - ">="
89
82
  - !ruby/object:Gem::Version
90
83
  version: '0'
91
- segments:
92
- - 0
93
- hash: -3364554805105049379
94
84
  required_rubygems_version: !ruby/object:Gem::Requirement
95
- none: false
96
85
  requirements:
97
- - - ! '>='
86
+ - - ">="
98
87
  - !ruby/object:Gem::Version
99
88
  version: '0'
100
- segments:
101
- - 0
102
- hash: -3364554805105049379
103
89
  requirements: []
104
90
  rubyforge_project:
105
- rubygems_version: 1.8.25
91
+ rubygems_version: 2.6.14
106
92
  signing_key:
107
- specification_version: 3
93
+ specification_version: 4
108
94
  summary: Calculate the contrast ratio between 2 colors, for checking against the WCAG
109
95
  recommended contrast ratio for legibility.
110
96
  test_files: