Skip to content

Commit

Permalink
Apply rubocop suggestions.
Browse files Browse the repository at this point in the history
  • Loading branch information
fnando committed Aug 31, 2016
1 parent d36174e commit 2565ccc
Show file tree
Hide file tree
Showing 20 changed files with 51 additions and 132 deletions.
110 changes: 0 additions & 110 deletions .hound.yml

This file was deleted.

15 changes: 14 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
AllCops:
Exclude:
- "bin/**/*"
- "gemfiles/**/*"
- "vendor/**/*"
- "Gemfile"
- "Rakefile"
- "*.gemspec"
- "config.ru"

Style/Alias:
EnforcedStyle: prefer_alias_method

Style/FrozenStringLiteralComment:
EnforcedStyle: always

Expand Down Expand Up @@ -58,7 +71,7 @@ SingleLineBlockParams:
VariableInterpolation:
Enabled: false

TrailingComma:
Style/TrailingCommaInLiteral:
Enabled: false

WhileUntilModifier:
Expand Down
8 changes: 7 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ Rake::TestTask.new(:test) do |t|
t.ruby_opts = %w[-rubygems]
end

require "rubocop/rake_task"
desc "Run rubocop"
task :rubocop do
RuboCop::RakeTask.new
end

desc "Run specs against all gemfiles"
task "test:all" do
%w[
Expand All @@ -23,4 +29,4 @@ task "test:all" do
end
end

task default: "test"
task default: [:test, :rubocop]
1 change: 1 addition & 0 deletions browser.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ Gem::Specification.new do |s|
s.add_development_dependency "pry-meta"
s.add_development_dependency "minitest-autotest"
s.add_development_dependency "codeclimate-test-reporter"
s.add_development_dependency "rubocop"
end
1 change: 1 addition & 0 deletions lib/browser/alipay.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module Browser
class Alipay < Base
def id
Expand Down
4 changes: 2 additions & 2 deletions lib/browser/detect_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ def detect_version?(actual_version, expected_version)
actual_version = parse_version(actual_version)

Gem::Requirement.create(expected_version)
.satisfied_by?(Gem::Version.create(actual_version))
.satisfied_by?(Gem::Version.create(actual_version))
end

def parse_version(version)
version.kind_of?(Numeric) ? "#{version}" : version
version.kind_of?(Numeric) ? version.to_s : version
end
end
end
4 changes: 2 additions & 2 deletions lib/browser/device.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def initialize(ua)

def subject
@subject ||= self.class.matchers
.map {|matcher| matcher.new(ua) }
.find(&:match?)
.map {|matcher| matcher.new(ua) }
.find(&:match?)
end

def id
Expand Down
2 changes: 1 addition & 1 deletion lib/browser/generic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Generic < Base
NAMES = {
"QuickTime" => "QuickTime",
"CoreMedia" => "Apple CoreMedia"
}
}.freeze

def id
:generic
Expand Down
2 changes: 1 addition & 1 deletion lib/browser/internet_explorer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class InternetExplorer < Base
"6.0" => "10",
"7.0" => "11",
"8.0" => "12"
}
}.freeze

def id
:ie
Expand Down
2 changes: 1 addition & 1 deletion lib/browser/micro_messenger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ def match?
ua =~ /MicroMessenger/i
end
end
end
end
2 changes: 1 addition & 1 deletion lib/browser/middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Middleware
ACCEPT_REGEX = %r[(text/html|\*/\*)]

def initialize(app, &block)
fail ArgumentError, "Browser::Middleware requires a block" unless block
raise ArgumentError, "Browser::Middleware requires a block" unless block

@app = app
@block = block
Expand Down
4 changes: 2 additions & 2 deletions lib/browser/platform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def initialize(ua)

def subject
@subject ||= self.class.matchers
.map {|matcher| matcher.new(ua) }
.find(&:match?)
.map {|matcher| matcher.new(ua) }
.find(&:match?)
end

def adobe_air?
Expand Down
2 changes: 1 addition & 1 deletion lib/browser/platform/mac.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Browser
class Platform
class Mac < Base
def version
(ua[/Mac OS X\s*([0-9_\.]+)?/, 1] || "0").gsub("_", ".")
(ua[/Mac OS X\s*([0-9_\.]+)?/, 1] || "0").tr("_", ".")
end

def name
Expand Down
4 changes: 3 additions & 1 deletion lib/browser/testing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ def self.bot_user_agents
end

def self.search_engine_user_agents
@search_engine_user_agents ||= YAML.load_file(Browser.root.join("test/ua_search_engines.yml"))
@search_engine_user_agents ||= begin
YAML.load_file(Browser.root.join("test/ua_search_engines.yml"))
end
end

def self.[](key)
Expand Down
2 changes: 1 addition & 1 deletion lib/browser/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: true
module Browser
VERSION = "2.2.0"
VERSION = "2.2.0".freeze
end
7 changes: 5 additions & 2 deletions test/browser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,11 @@ class BrowserTest < Minitest::Test
end

test "returns all known languages" do
browser = Browser.new("", accept_language: "en-us,en;q=0.8,pt-br;q=0.5,pt;q=0.3")
assert_equal ["en-US", "en", "pt-BR", "pt"], browser.accept_language.map(&:full)
accept_language = "en-us,en;q=0.8,pt-br;q=0.5,pt;q=0.3"
browser = Browser.new("", accept_language: accept_language)
languages = browser.accept_language.map(&:full)

assert_equal ["en-US", "en", "pt-BR", "pt"], languages
end

test "removes duplicate items" do
Expand Down
9 changes: 6 additions & 3 deletions test/unit/accept_language_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ def assert_language(item, expect = {})
end

test "parses complex set" do
result = Browser::AcceptLanguage.parse("fr-CA,fr;q=0.8,en-US;q=0.6,en;q=0.4,*;q=0.1")
accept_language = "fr-CA,fr;q=0.8,en-US;q=0.6,en;q=0.4,*;q=0.1"
result = Browser::AcceptLanguage.parse(accept_language)

assert_language result[0], code: "fr", region: "CA", quality: 1.0
assert_language result[1], code: "fr", region: nil, quality: 0.8
Expand All @@ -72,7 +73,8 @@ def assert_language(item, expect = {})
end

test "handles random white spaces" do
result = Browser::AcceptLanguage.parse("fr-CA, fr;q=0.8, en-US;q=0.6,en;q=0.4, *;q=0.1")
accept_language = "fr-CA, fr;q=0.8, en-US;q=0.6,en;q=0.4, *;q=0.1"
result = Browser::AcceptLanguage.parse(accept_language)

assert_language result[0], code: "fr", region: "CA", quality: 1.0
assert_language result[1], code: "fr", region: nil, quality: 0.8
Expand All @@ -82,7 +84,8 @@ def assert_language(item, expect = {})
end

test "sorts based on quality" do
result = Browser::AcceptLanguage.parse("fr-CA,fr;q=0.2,en-US;q=0.6,en;q=0.4,*;q=0.5")
accept_language = "fr-CA,fr;q=0.2,en-US;q=0.6,en;q=0.4,*;q=0.5"
result = Browser::AcceptLanguage.parse(accept_language)

assert_language result[0], code: "fr", region: "CA", quality: 1.0
assert_language result[1], code: "en", region: "US", quality: 0.6
Expand Down
2 changes: 0 additions & 2 deletions test/unit/alipay_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
class AlipayTest < Minitest::Test
test "detects alipay iOS" do
browser = Browser.new(Browser["ALIPAY_IOS"])
puts browser.id
puts browser.name

assert_equal :alipay, browser.id
assert browser.alipay?
Expand Down
1 change: 1 addition & 0 deletions test/unit/generic_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require "test_helper"

class GenericTest < Minitest::Test
Expand Down
1 change: 1 addition & 0 deletions test/unit/meta_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require "test_helper"

class MetaTest < Minitest::Test
Expand Down

0 comments on commit 2565ccc

Please sign in to comment.