-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add rubocop linter and fix styles #4
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,3 +39,6 @@ jobs: | |
|
||
- name: Test | ||
run: bundle exec rspec | ||
|
||
- name: Run Rubocop linter | ||
run: bundle exec rubocop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# .rubocop.yml | ||
|
||
AllCops: | ||
NewCops: enable | ||
|
||
Naming/MethodParameterName: | ||
Enabled: false | ||
|
||
Metrics/ParameterLists: | ||
Enabled: false | ||
|
||
Metrics/PerceivedComplexity: | ||
Enabled: false | ||
|
||
Metrics/AbcSize: | ||
Enabled: false | ||
|
||
Style/OptionalBooleanParameter: | ||
Enabled: false | ||
|
||
Metrics/BlockLength: | ||
Enabled: false | ||
|
||
Metrics/ClassLength: | ||
Enabled: false | ||
|
||
Metrics/CyclomaticComplexity: | ||
Enabled: false | ||
|
||
Metrics/MethodLength: | ||
Enabled: false | ||
|
||
Naming/VariableNumber: | ||
Enabled: false | ||
|
||
Gemspec/DevelopmentDependencies: | ||
EnforcedStyle: gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
source "https://rubygems.org" | ||
git_source(:github) { |repo| "https://github.com/butteff/is_dark_ruby_gem.git" } | ||
# frozen_string_literal: true | ||
|
||
gem "rmagick" | ||
source 'https://rubygems.org' | ||
git_source(:github) { |_repo| 'https://github.com/butteff/is_dark_ruby_gem.git' } | ||
|
||
group :development, :test do | ||
gem "rspec" | ||
gem "minitest" | ||
end | ||
# Specify your gem's dependencies in scenic.gemspec | ||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
require "rake/testtask" | ||
# frozen_string_literal: true | ||
|
||
require 'rake/testtask' | ||
|
||
Rake::TestTask.new do |t| | ||
t.libs << "test" | ||
t.libs << 'test' | ||
end | ||
|
||
desc "Run tests" | ||
task default: :test | ||
desc 'Run tests' | ||
task default: :test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
Gem::Specification.new do |s| | ||
s.name = "is_dark" | ||
s.version = "0.1.7" | ||
s.summary = "Detects a dark background under an area or by a color code" | ||
s.description = "Detects a dark color based on luminance W3 standarts ( https://www.w3.org/TR/WCAG20/#relativeluminancedef ). \n\n It has these options: \n * is a hex color dark \n * is an Imagick pixel dark \n * is an Imagick pixel from a blob dark \n * is an area in a blob over a dark background (uses Imagick for it too). \n\n An example practical aspect: it can be useful to understand will a black colored text be visible or not over an area." | ||
s.authors = ["Sergei Illarionov", "Liamshin Ilia"] | ||
s.email = "butteff.ru@gmail.com" | ||
s.files = ["lib/is_dark.rb"] | ||
s.homepage = "https://butteff.ru/en/" | ||
s.post_install_message = "You can find docs about is_dark gem on https://butteff.ru/en/extensions or on https://github.com/butteff/is_dark_ruby_gem" | ||
s.license = "MIT" | ||
s.metadata = { "source_code_uri" => "https://github.com/butteff/is_dark_ruby_gem" } | ||
s.name = 'is_dark' | ||
s.version = '0.1.7' | ||
s.summary = 'Detects a dark background under an area or by a color code' | ||
s.description = 'Detects a dark color based on luminance W3 standarts ' \ | ||
"( https://www.w3.org/TR/WCAG20/#relativeluminancedef ). \n\n " \ | ||
"It has these options: \n * is a hex color dark \n * is an Imagick " \ | ||
"pixel dark \n * is an Imagick pixel from a blob dark \n * is an area " \ | ||
"in a blob over a dark background (uses Imagick for it too). \n\n " \ | ||
'An example practical aspect: it can be useful to understand will ' \ | ||
'a black colored text be visible or not over an area.' | ||
s.authors = ['Sergei Illarionov', 'Liamshin Ilia'] | ||
s.email = 'butteff.ru@gmail.com' | ||
s.files = ['lib/is_dark.rb'] | ||
s.homepage = 'https://butteff.ru/en/' | ||
s.post_install_message = 'You can find docs about is_dark gem on https://butteff.ru/en/extensions or on https://github.com/butteff/is_dark_ruby_gem' | ||
s.license = 'MIT' | ||
s.metadata = { 'source_code_uri' => 'https://github.com/butteff/is_dark_ruby_gem', | ||
'rubygems_mfa_required' => 'true' } | ||
s.required_ruby_version = '>= 2.7.0' | ||
s.add_dependency 'rmagick', '~> 5.2' | ||
s.add_development_dependency 'rspec', "~> 3.13" | ||
s.add_development_dependency 'minitest', "~> 5.16" | ||
s.add_development_dependency 'minitest', '~> 5.16' | ||
s.add_development_dependency 'rspec', '~> 3.13' | ||
s.add_development_dependency 'rubocop', '~> 1.69' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,125 +1,134 @@ | ||
require "rmagick" | ||
# frozen_string_literal: true | ||
|
||
require 'rmagick' | ||
require 'spec_helper' | ||
require_relative '../../lib/is_dark' | ||
|
||
TEST_FILE_PATH = 'color_card.pdf' | ||
|
||
describe IsDark do | ||
|
||
describe ".color" do | ||
context "dark colors tests" do | ||
it "this color #000000 is dark, returns true" do | ||
describe '.color' do | ||
context 'dark colors tests' do | ||
it 'this color #000000 is dark, returns true' do | ||
expect(IsDark.color('#000000')).to eq(true) | ||
end | ||
|
||
it "this color #111111 is dark, returns true" do | ||
it 'this color #111111 is dark, returns true' do | ||
expect(IsDark.color('#111111')).to eq(true) | ||
end | ||
|
||
it "this color #102694 is dark, returns true" do | ||
it 'this color #102694 is dark, returns true' do | ||
expect(IsDark.color('#102694')).to eq(true) | ||
end | ||
|
||
it "this color #ff2e17 is dark, returns true" do | ||
it 'this color #ff2e17 is dark, returns true' do | ||
expect(IsDark.color('#800f03')).to eq(true) | ||
end | ||
end | ||
|
||
context "not dark colors tests" do | ||
it "this color is not dark, returns false" do | ||
context 'not dark colors tests' do | ||
it 'this color is not dark, returns false' do | ||
expect(IsDark.color('#444444')).to eq(false) | ||
end | ||
|
||
it "this color is not dark, returns false" do | ||
it 'this color is not dark, returns false' do | ||
expect(IsDark.color('#888888')).to eq(false) | ||
end | ||
|
||
it "this color is not dark, returns false" do | ||
it 'this color is not dark, returns false' do | ||
expect(IsDark.color('#ffffff')).to eq(false) | ||
end | ||
|
||
it "this color is not dark, returns false" do | ||
it 'this color is not dark, returns false' do | ||
expect(IsDark.color('#fff6b2')).to eq(false) | ||
end | ||
end | ||
end | ||
|
||
describe ".magick_pixel_from_blob" do | ||
context "test dark pixel" do | ||
it "this pixel is dark, returns true" do | ||
describe '.magick_pixel_from_blob' do | ||
context 'test dark pixel' do | ||
it 'this pixel is dark, returns true' do | ||
x = 120 | ||
y = 120 | ||
expect(IsDark.magick_pixel_from_blob(x, y, TEST_FILE_PATH)).to eq(true) | ||
end | ||
end | ||
|
||
context "test not dark pixel" do | ||
it "this pixel is not dark, returns false" do | ||
context 'test not dark pixel' do | ||
it 'this pixel is not dark, returns false' do | ||
x = 720 | ||
y = 120 | ||
expect(IsDark.magick_pixel_from_blob(x, y, TEST_FILE_PATH)).to eq(false) | ||
end | ||
end | ||
end | ||
|
||
describe ".magick_pixel" do | ||
context "test dark pixel" do | ||
it "this pixel is dark, returns true" do | ||
describe '.magick_pixel' do | ||
context 'test dark pixel' do | ||
it 'this pixel is dark, returns true' do | ||
image = Magick::Image.read(TEST_FILE_PATH).first | ||
pix = image.pixel_color(80, 320) | ||
expect(IsDark.magick_pixel(pix)).to eq(true) | ||
end | ||
end | ||
|
||
context "test not dark pixel" do | ||
it "this pixel is not dark, returns false" do | ||
context 'test not dark pixel' do | ||
it 'this pixel is not dark, returns false' do | ||
image = Magick::Image.read(TEST_FILE_PATH).first | ||
pix = image.pixel_color(720, 120) | ||
expect(IsDark.magick_pixel(pix)).to eq(false) | ||
end | ||
end | ||
end | ||
|
||
describe ".magick_area_from_blob" do | ||
context "test dark area" do | ||
it "this area is dark, returns true" do | ||
x = 120 #coordinate of a left corner of the area's rectangle X | ||
y = 120 #coordinate of a left corner of the area's rectangle Y | ||
cf_height = 64 #height of the area's rectangle | ||
cf_width = 128 #height of the area's rectangle | ||
percent = 70 #percent of detected dark pixels to invert | ||
matrix = (1..10) #matrix of dots. Range of matrix to build dots 1..10 - means 10x10 | ||
with_not_detected = false #Sometimes Imagick can't detect a pixel or it has no color, so it detects it as (RGB: 0,0,0), the gem has an option to consider pixels like this as "white", but if you need to disable this option add true or false | ||
expect(IsDark.magick_area_from_blob(x, y, TEST_FILE_PATH, cf_height, cf_width, percent, matrix, with_not_detected)).to eq(false) | ||
describe '.magick_area_from_blob' do | ||
context 'test dark area' do | ||
it 'this area is dark, returns true' do | ||
x = 120 # coordinate of a left corner of the area's rectangle X | ||
y = 120 # coordinate of a left corner of the area's rectangle Y | ||
cf_height = 64 # height of the area's rectangle | ||
cf_width = 128 # height of the area's rectangle | ||
percent = 70 # percent of detected dark pixels to invert | ||
matrix = (1..10) # matrix of dots. Range of matrix to build dots 1..10 - means 10x10 | ||
# Sometimes Imagick can't detect a pixel or it has no color, so it detects it as (RGB: 0,0,0), the gem has an | ||
# option to consider pixels like this as "white", but if you need to disable this option add true or false. | ||
with_not_detected = false | ||
expect(IsDark.magick_area_from_blob(x, y, TEST_FILE_PATH, cf_height, cf_width, percent, matrix, | ||
with_not_detected)).to eq(false) | ||
end | ||
end | ||
|
||
context "test bright area" do | ||
it "this area is not dark, returns false" do | ||
x = 720 #coordinate of a left corner of the area's rectangle X | ||
y = 120 #coordinate of a left corner of the area's rectangle Y | ||
cf_height = 64 #height of the area's rectangle | ||
cf_width = 128 #height of the area's rectangle | ||
percent = 70 #percent of detected dark pixels to invert | ||
matrix = (1..10) #matrix of dots. Range of matrix to build dots 1..10 - means 10x10 | ||
with_not_detected = false #Sometimes Imagick can't detect a pixel or it has no color, so it detects it as (RGB: 0,0,0), the gem has an option to consider pixels like this as "white", but if you need to disable this option add true or false | ||
expect(IsDark.magick_area_from_blob(x, y, TEST_FILE_PATH, cf_height, cf_width, percent, matrix, with_not_detected)).to eq(false) | ||
context 'test bright area' do | ||
it 'this area is not dark, returns false' do | ||
x = 720 # coordinate of a left corner of the area's rectangle X | ||
y = 120 # coordinate of a left corner of the area's rectangle Y | ||
cf_height = 64 # height of the area's rectangle | ||
cf_width = 128 # height of the area's rectangle | ||
percent = 70 # percent of detected dark pixels to invert | ||
matrix = (1..10) # matrix of dots. Range of matrix to build dots 1..10 - means 10x10 | ||
# Sometimes Imagick can't detect a pixel or it has no color, so it detects it as (RGB: 0,0,0), the gem has | ||
# an option to consider pixels like this as "white", but if you need to disable this option add true or false. | ||
with_not_detected = false | ||
expect(IsDark.magick_area_from_blob(x, y, TEST_FILE_PATH, cf_height, cf_width, percent, matrix, | ||
with_not_detected)).to eq(false) | ||
end | ||
end | ||
|
||
context "test debug output" do | ||
it "test area with logs and debug file" do | ||
x = 120 #coordinate of a left corner of the area's rectangle X | ||
y = 120 #coordinate of a left corner of the area's rectangle Y | ||
cf_height = 64 #height of the area's rectangle | ||
cf_width = 128 #height of the area's rectangle | ||
percent = 70 #percent of detected dark pixels to invert | ||
matrix = (1..10) #matrix of dots. Range of matrix to build dots 1..10 - means 10x10 | ||
with_not_detected = false #Sometimes Imagick can't detect a pixel or it has no color, so it detects it as (RGB: 0,0,0), the gem has an option to consider pixels like this as "white", but if you need to disable this option add true or false | ||
context 'test debug output' do | ||
it 'test area with logs and debug file' do | ||
x = 120 # coordinate of a left corner of the area's rectangle X | ||
y = 120 # coordinate of a left corner of the area's rectangle Y | ||
cf_height = 64 # height of the area's rectangle | ||
cf_width = 128 # height of the area's rectangle | ||
percent = 70 # percent of detected dark pixels to invert | ||
matrix = (1..10) # matrix of dots. Range of matrix to build dots 1..10 - means 10x10 | ||
# Sometimes Imagick can't detect a pixel or it has no color, so it detects it as (RGB: 0,0,0), the gem has | ||
# an option to consider pixels like this as "white", but if you need to disable this option add true or false. | ||
with_not_detected = false | ||
IsDark.set_debug_data(true, './is_dark_debug_output.pdf') | ||
expect(IsDark.magick_area_from_blob(x, y, TEST_FILE_PATH, cf_height, cf_width, percent, matrix, with_not_detected)).to eq(false) | ||
expect(IsDark.magick_area_from_blob(x, y, TEST_FILE_PATH, cf_height, cf_width, percent, matrix, | ||
with_not_detected)).to eq(false) | ||
end | ||
end | ||
end | ||
|
||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In further refactoring, I propose enabling some of the currently disabled cops.