ronin-web-user_agents 0.1.0.beta1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 211ce690829536496ff38bb3b42eeb7aca3fc6288e43def11bfbba17f28895e5
4
- data.tar.gz: e9085b315d3f470f0d521864926ded3bdbfd0c2ea033d19795abace19645a294
3
+ metadata.gz: 362b831e0de6d339b41a3c12fd0c80cc542f250ddb8cb00304a10b9efe4f4d05
4
+ data.tar.gz: 2f56546e867a79c8a9a1393261f2b4546c70f192d93736c7499ecf2289961f84
5
5
  SHA512:
6
- metadata.gz: a4690d6f464cae3c3fb33a2ab1904147ec2c41cd148e90a609b52e3bf28d8ef7b5bf3197a2c88de88b56b67cb6aca6d4bab08c564692d9341df658f035685d5b
7
- data.tar.gz: 531decd58766e34c94b7e558b1bc3d2ef236edaf354e48f9b663e1ed8a7ee87d71d98f543962a71278a0f5f21a604511d4f2255cca8e2dda9b9612b4905a4333
6
+ metadata.gz: 69d452562cbf97cb037ece1d94e364ab39aff4458295cc5339140307248962838a24e87dcec8cc11abc9c1f1c6574c512177f16a142bfc445b7be1a6b9076e5a
7
+ data.tar.gz: 708c8b9ca36740ca6d8a90eb5bd7059e521e9f98b46af10aa7fc07b2c65c1a99ade85e1befcd5b30fade7e204ad0d076a0e6b66116bb9d277a08d7c4ff5fe0d4
@@ -12,15 +12,18 @@ jobs:
12
12
  - '3.0'
13
13
  - '3.1'
14
14
  - '3.2'
15
+ - '3.3'
16
+ - '3.4'
15
17
  - jruby
16
18
  - truffleruby
17
19
  name: Ruby ${{ matrix.ruby }}
18
20
  steps:
19
- - uses: actions/checkout@v2
21
+ - uses: actions/checkout@v4
20
22
  - name: Set up Ruby
21
23
  uses: ruby/setup-ruby@v1
22
24
  with:
23
25
  ruby-version: ${{ matrix.ruby }}
26
+ bundler-cache: true
24
27
  - name: Install libsqlite3
25
28
  run: |
26
29
  sudo apt update -y && \
@@ -29,3 +32,17 @@ jobs:
29
32
  run: bundle install --jobs 4 --retry 3
30
33
  - name: Run tests
31
34
  run: bundle exec rake test
35
+
36
+ # rubocop linting
37
+ rubocop:
38
+ runs-on: ubuntu-latest
39
+ steps:
40
+ - uses: actions/checkout@v4
41
+ - name: Set up Ruby
42
+ uses: ruby/setup-ruby@v1
43
+ with:
44
+ ruby-version: 3.0
45
+ - name: Install dependencies
46
+ run: bundle install --jobs 4 --retry 3
47
+ - name: Run rubocop
48
+ run: bundle exec rubocop --parallel
data/.rubocop.yml ADDED
@@ -0,0 +1,11 @@
1
+ AllCops:
2
+ NewCops: enable
3
+ SuggestExtensions: false
4
+ TargetRubyVersion: 3.1
5
+
6
+ inherit_gem:
7
+ rubocop-ronin: rubocop.yml
8
+
9
+ #
10
+ # ronin-FIXME specific exceptions
11
+ #
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-3.1
1
+ ruby-3.3
data/.yardopts CHANGED
@@ -1 +1 @@
1
- --markup markdown --title 'Ronin Web UserAgents Documentation' --protected
1
+ --markup markdown --title 'Ronin::Web::UserAgents Documentation' --protected
data/ChangeLog.md CHANGED
@@ -1,5 +1,12 @@
1
- ### 0.1.0 / 2023-XX-XX
1
+ ### 0.1.1 / 2025-02-14
2
2
 
3
+ * Use `require_relative` to improve load times.
4
+
5
+ ### 0.1.0 / 2023-02-01
6
+
7
+ * Extracted and refactored from [ronin-web](https://github.com/ronin-rb/ronin-web/tree/v0.3.0.rc1).
8
+ * Relicensed as LGPL-3.0.
3
9
  * Initial release:
10
+ * Requires `ruby` >= 3.0.0.
4
11
  * Generates random but realistic `User-Agent` strings from known values.
5
12
 
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  gemspec
@@ -23,4 +25,6 @@ group :development do
23
25
  gem 'dead_end', require: false
24
26
  gem 'sord', require: false, platform: :mri
25
27
  gem 'stackprof', require: false, platform: :mri
28
+ gem 'rubocop', require: false, platform: :mri
29
+ gem 'rubocop-ronin', require: false, platform: :mri
26
30
  end
data/README.md CHANGED
@@ -2,13 +2,13 @@
2
2
 
3
3
  [![CI](https://github.com/ronin-rb/ronin-web-user_agents/actions/workflows/ruby.yml/badge.svg)](https://github.com/ronin-rb/ronin-web-user_agents/actions/workflows/ruby.yml)
4
4
  [![Code Climate](https://codeclimate.com/github/ronin-rb/ronin-web-user_agents.svg)](https://codeclimate.com/github/ronin-rb/ronin-web-user_agents)
5
+ [![Gem Version](https://badge.fury.io/rb/ronin-web-user_agents.svg)](https://badge.fury.io/rb/ronin-web-user_agents)
5
6
 
6
7
  * [Website](https://ronin-rb.dev/)
7
8
  * [Source](https://github.com/ronin-rb/ronin-web-user_agents)
8
9
  * [Issues](https://github.com/ronin-rb/ronin-web-user_agents/issues)
9
10
  * [Documentation](https://ronin-rb.dev/docs/ronin-web-user_agents/frames)
10
11
  * [Discord](https://discord.gg/6WAb3PsVX9) |
11
- [Twitter](https://twitter.com/ronin_rb) |
12
12
  [Mastodon](https://infosec.exchange/@ronin_rb)
13
13
 
14
14
  ## Description
@@ -44,8 +44,7 @@ user_agent = Ronin::Web::UserAgents.chrome.random
44
44
  Build a specific Chrome `User-Agent` for Android 10.0 string:
45
45
 
46
46
  ```ruby
47
- Ronin::Web::UserAgents.chrome.build(chrome_version: '100.0.4758.81', os: :
48
- android, os_version: '10.0')
47
+ Ronin::Web::UserAgents.chrome.build(chrome_version: '100.0.4758.81', os: :android, os_version: '10.0')
49
48
  # => "Mozilla/5.0 (Linux; Android 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4758.81 Mobile Safari/537.36"
50
49
  ```
51
50
 
@@ -114,7 +113,7 @@ RestClient.get "https://www.whatismybrowser.com/detect/what-is-my-user-agent",
114
113
  Spoof `curl`'s `User-Agent` string:
115
114
 
116
115
  ```shell
117
- user_agent="$(ruby -Ilib -r ronin/web/user_agents -e 'print Ronin::Web::UserAgents.chrome.random')"
116
+ user_agent="$(ruby -r ronin/web/user_agents -e 'print Ronin::Web::UserAgents.chrome.random')"
118
117
 
119
118
  curl --user-agent "$user_agent" https://www.whatismybrowser.com/detect/what-is-my-user-agent
120
119
  ```
@@ -159,7 +158,7 @@ gem.add_dependency 'ronin-web-user_agents', '~> 0.1'
159
158
 
160
159
  ## License
161
160
 
162
- Copyright (c) 2006-2022 Hal Brodigan (postmodern.mod3@gmail.com)
161
+ Copyright (c) 2006-2025 Hal Brodigan (postmodern.mod3@gmail.com)
163
162
 
164
163
  ronin-web-user_agents is free software: you can redistribute it and/or modify
165
164
  it under the terms of the GNU Lesser General Public License as published
data/Rakefile CHANGED
@@ -1,11 +1,11 @@
1
- require 'rubygems'
1
+ # frozen_string_literal: true
2
2
 
3
3
  begin
4
4
  require 'bundler'
5
5
  rescue LoadError => e
6
6
  warn e.message
7
7
  warn "Run `gem install bundler` to install Bundler"
8
- exit -1
8
+ exit(-1)
9
9
  end
10
10
 
11
11
  begin
data/gemspec.yml CHANGED
@@ -1,18 +1,18 @@
1
1
  name: ronin-web-user_agents
2
- summary: generate random User-Agent strings
2
+ summary: Generate random but realistic User-Agent strings
3
3
  description: Yet another User-Agent string generator library.
4
4
 
5
- license: LGPL-3.0
5
+ license: LGPL-3.0-or-later
6
6
  authors: Postmodern
7
7
  email: postmodern.mod3@gmail.com
8
8
  homepage: https://ronin-rb.dev/
9
9
  has_yard: true
10
10
 
11
11
  metadata:
12
- documentation_uri: https://rubydoc.info/gems/ronin-web-user_agents
12
+ documentation_uri: https://ronin-rb.dev/docs/ronin-web-user_agents
13
13
  source_code_uri: https://github.com/ronin-rb/ronin-web-user_agents
14
14
  bug_tracker_uri: https://github.com/ronin-rb/ronin-web-user_agents/issues
15
- changelog_uri: https://github.com/ronin-rb/ronin-web-user_agents/blob/master/ChangeLog.md
15
+ changelog_uri: https://github.com/ronin-rb/ronin-web-user_agents/blob/main/ChangeLog.md
16
16
  rubygems_mfa_required: 'true'
17
17
 
18
18
  required_ruby_version: ">= 3.0.0"
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # ronin-web-user_agents - Yet another User-Agent string generator library.
4
4
  #
5
- # Copyright (c) 2006-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ # Copyright (c) 2006-2025 Hal Brodigan (postmodern.mod3 at gmail.com)
6
6
  #
7
7
  # ronin-web-user_agents is free software: you can redistribute it and/or modify
8
8
  # it under the terms of the GNU Lesser General Public License as published
@@ -18,10 +18,10 @@
18
18
  # along with ronin-web-user_agents. If not, see <https://www.gnu.org/licenses/>
19
19
  #
20
20
 
21
- require 'ronin/web/user_agents/os/windows'
22
- require 'ronin/web/user_agents/os/mac_os'
23
- require 'ronin/web/user_agents/os/linux'
24
- require 'ronin/web/user_agents/os/android'
21
+ require_relative 'os/windows'
22
+ require_relative 'os/mac_os'
23
+ require_relative 'os/linux'
24
+ require_relative 'os/android'
25
25
 
26
26
  module Ronin
27
27
  module Web
@@ -30,7 +30,6 @@ module Ronin
30
30
  # Represents every possible Chrome `User-Agent` string.
31
31
  #
32
32
  module Chrome
33
-
34
33
  #
35
34
  # Builds a new Chrome `User-Agent` string.
36
35
  #
@@ -186,8 +185,6 @@ module Ronin
186
185
  )
187
186
  end
188
187
 
189
- private
190
-
191
188
  #
192
189
  # Builds a Chrome `User-Agent` string for Windows.
193
190
  #
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # ronin-web-user_agents - Yet another User-Agent string generator library.
4
4
  #
5
- # Copyright (c) 2006-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ # Copyright (c) 2006-2025 Hal Brodigan (postmodern.mod3 at gmail.com)
6
6
  #
7
7
  # ronin-web-user_agents is free software: you can redistribute it and/or modify
8
8
  # it under the terms of the GNU Lesser General Public License as published
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # ronin-web-user_agents - Yet another User-Agent string generator library.
4
4
  #
5
- # Copyright (c) 2006-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ # Copyright (c) 2006-2025 Hal Brodigan (postmodern.mod3 at gmail.com)
6
6
  #
7
7
  # ronin-web-user_agents is free software: you can redistribute it and/or modify
8
8
  # it under the terms of the GNU Lesser General Public License as published
@@ -18,11 +18,11 @@
18
18
  # along with ronin-web-user_agents. If not, see <https://www.gnu.org/licenses/>
19
19
  #
20
20
 
21
- require 'ronin/web/user_agents/os/windows'
22
- require 'ronin/web/user_agents/os/mac_os'
23
- require 'ronin/web/user_agents/os/linux'
24
- require 'ronin/web/user_agents/os/android'
25
- require 'ronin/web/user_agents/data_dir'
21
+ require_relative 'os/windows'
22
+ require_relative 'os/mac_os'
23
+ require_relative 'os/linux'
24
+ require_relative 'os/android'
25
+ require_relative 'data_dir'
26
26
 
27
27
  module Ronin
28
28
  module Web
@@ -33,7 +33,6 @@ module Ronin
33
33
  # @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent/Firefox
34
34
  #
35
35
  module Firefox
36
-
37
36
  # The default `Gecko/...` version.
38
37
  #
39
38
  # @note: On desktop, the `Gecko/...` version is hardcoded to `20100101`
@@ -244,8 +243,6 @@ module Ronin
244
243
  )
245
244
  end
246
245
 
247
- private
248
-
249
246
  #
250
247
  # Builds a Firefox `User-Agent` string for Windows.
251
248
  #
@@ -319,12 +316,12 @@ module Ronin
319
316
  #
320
317
  def self.build_linux(encryption: nil, linux_distro: nil, arch: nil, lang: nil, firefox_version: )
321
318
  encryption_flag = ENCRYPTION.fetch(encryption)
322
- linux_arch = OS::Linux::ARCHES[arch]
323
- linux_distro = OS::Linux::DISTROS.fetch(linux_distro,linux_distro)
319
+ linux_arch = OS::Linux::ARCHES[arch]
320
+ linux_distro = OS::Linux::DISTROS.fetch(linux_distro,linux_distro)
324
321
 
325
322
  extensions = String.new("X11")
326
323
  extensions << "; #{encryption_flag}" if encryption_flag
327
- extensions << "; #{linux_distro}" if linux_distro
324
+ extensions << "; #{linux_distro}" if linux_distro
328
325
  extensions << "; Linux"
329
326
  extensions << " #{linux_arch}" if linux_arch
330
327
  extensions << "; #{lang}" if lang
@@ -353,7 +350,6 @@ module Ronin
353
350
 
354
351
  return "Mozilla/5.0 (#{extensions}) Gecko/#{firefox_version} Firefox/#{firefox_version}"
355
352
  end
356
-
357
353
  end
358
354
  end
359
355
  end
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # ronin-web-user_agents - Yet another User-Agent string generator library.
4
4
  #
5
- # Copyright (c) 2006-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ # Copyright (c) 2006-2025 Hal Brodigan (postmodern.mod3 at gmail.com)
6
6
  #
7
7
  # ronin-web-user_agents is free software: you can redistribute it and/or modify
8
8
  # it under the terms of the GNU Lesser General Public License as published
@@ -18,7 +18,7 @@
18
18
  # along with ronin-web-user_agents. If not, see <https://www.gnu.org/licenses/>
19
19
  #
20
20
 
21
- require 'ronin/web/user_agents/chrome'
21
+ require_relative 'chrome'
22
22
 
23
23
  module Ronin
24
24
  module Web
@@ -64,7 +64,6 @@ module Ronin
64
64
  # @api public
65
65
  #
66
66
  def self.build(crawler: :search, compatible: nil, chrome_version: nil)
67
-
68
67
  case crawler
69
68
  when :image
70
69
  "Googlebot-Image/1.0"
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # ronin-web-user_agents - Yet another User-Agent string generator library.
4
4
  #
5
- # Copyright (c) 2006-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ # Copyright (c) 2006-2025 Hal Brodigan (postmodern.mod3 at gmail.com)
6
6
  #
7
7
  # ronin-web-user_agents is free software: you can redistribute it and/or modify
8
8
  # it under the terms of the GNU Lesser General Public License as published
@@ -18,7 +18,7 @@
18
18
  # along with ronin-web-user_agents. If not, see <https://www.gnu.org/licenses/>
19
19
  #
20
20
 
21
- require 'ronin/web/user_agents/data_dir'
21
+ require_relative '../data_dir'
22
22
 
23
23
  module Ronin
24
24
  module Web
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # ronin-web-user_agents - Yet another User-Agent string generator library.
4
4
  #
5
- # Copyright (c) 2006-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ # Copyright (c) 2006-2025 Hal Brodigan (postmodern.mod3 at gmail.com)
6
6
  #
7
7
  # ronin-web-user_agents is free software: you can redistribute it and/or modify
8
8
  # it under the terms of the GNU Lesser General Public License as published
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # ronin-web-user_agents - Yet another User-Agent string generator library.
4
4
  #
5
- # Copyright (c) 2006-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ # Copyright (c) 2006-2025 Hal Brodigan (postmodern.mod3 at gmail.com)
6
6
  #
7
7
  # ronin-web-user_agents is free software: you can redistribute it and/or modify
8
8
  # it under the terms of the GNU Lesser General Public License as published
@@ -97,8 +97,10 @@ module Ronin
97
97
  '11.55' => '11_55',
98
98
  '11.6.3' => '11_6_3',
99
99
  '12.2.0' => '12_2_0',
100
- '16.55' => '16_55',
100
+ '16.55' => '16_55'
101
101
  }
102
+
103
+ # Set a default `VERSIONS_UNDERSCORED` rule of `X.Y` -> `X_Y`.
102
104
  VERSIONS_UNDERSCORED.default_proc = ->(hash,version) {
103
105
  version.tr('.','_')
104
106
  }
@@ -108,7 +110,6 @@ module Ronin
108
110
  intel: 'Intel',
109
111
  x86_64: 'Intel'
110
112
  }
111
-
112
113
  end
113
114
  end
114
115
  end
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # ronin-web-user_agents - Yet another User-Agent string generator library.
4
4
  #
5
- # Copyright (c) 2006-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ # Copyright (c) 2006-2025 Hal Brodigan (postmodern.mod3 at gmail.com)
6
6
  #
7
7
  # ronin-web-user_agents is free software: you can redistribute it and/or modify
8
8
  # it under the terms of the GNU Lesser General Public License as published
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # ronin-web-user_agents - Yet another User-Agent string generator library.
4
4
  #
5
- # Copyright (c) 2006-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ # Copyright (c) 2006-2025 Hal Brodigan (postmodern.mod3 at gmail.com)
6
6
  #
7
7
  # ronin-web-user_agents is free software: you can redistribute it and/or modify
8
8
  # it under the terms of the GNU Lesser General Public License as published
@@ -22,7 +22,7 @@ module Ronin
22
22
  module Web
23
23
  module UserAgents
24
24
  # ronin-web-user_agents version
25
- VERSION = '0.1.0.beta1'
25
+ VERSION = '0.1.1'
26
26
  end
27
27
  end
28
28
  end
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # ronin-web-user_agents - Yet another User-Agent string generator library.
4
4
  #
5
- # Copyright (c) 2006-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ # Copyright (c) 2006-2025 Hal Brodigan (postmodern.mod3 at gmail.com)
6
6
  #
7
7
  # ronin-web-user_agents is free software: you can redistribute it and/or modify
8
8
  # it under the terms of the GNU Lesser General Public License as published
@@ -19,13 +19,13 @@
19
19
  #
20
20
 
21
21
  # browsers
22
- require 'ronin/web/user_agents/chrome'
23
- require 'ronin/web/user_agents/firefox'
22
+ require_relative 'user_agents/chrome'
23
+ require_relative 'user_agents/firefox'
24
24
 
25
25
  # crawlers
26
- require 'ronin/web/user_agents/google_bot'
26
+ require_relative 'user_agents/google_bot'
27
27
 
28
- require 'ronin/web/user_agents/version'
28
+ require_relative 'user_agents/version'
29
29
 
30
30
  module Ronin
31
31
  module Web
@@ -55,7 +55,6 @@ module Ronin
55
55
  # # => "GoogleBot/2.1 (+http://www.google.com/bot.html)"
56
56
  #
57
57
  module UserAgents
58
-
59
58
  #
60
59
  # Google Chrome `User-Agent` strings.
61
60
  #
@@ -91,7 +90,7 @@ module Ronin
91
90
  #
92
91
  # @example
93
92
  # user_agent = Ronin::Web::UserAgents.firefox.random
94
- # # => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16.0; rv:52.55.07) Gecko/20100101 Firefox/52.55.07"
93
+ # # => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16.0; rv:52.55.07) Gecko/20100101 Firefox/52.55.07"
95
94
  #
96
95
  # @api public
97
96
  #
@@ -129,13 +128,13 @@ module Ronin
129
128
  # Ronin::Web::UserAgents.random
130
129
  # # => "Mozilla/5.0 (X11; Fedora; Linux i686; en-IE; rv:123.4) Gecko/20100101 Firefox/123.4"
131
130
  #
132
- def self.random(&block)
131
+ def self.random
133
132
  method = [
134
133
  :chrome,
135
- :firefox,
134
+ :firefox
136
135
  ].sample
137
136
 
138
- return send(method).random(&block)
137
+ return send(method).random
139
138
  end
140
139
  end
141
140
  end
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'yaml'
4
4
 
@@ -22,18 +22,19 @@ Gem::Specification.new do |gem|
22
22
  gem.homepage = gemspec['homepage']
23
23
  gem.metadata = gemspec['metadata'] if gemspec['metadata']
24
24
 
25
- glob = lambda { |patterns| gem.files & Dir[*patterns] }
25
+ glob = ->(patterns) { gem.files & Dir[*patterns] }
26
26
 
27
27
  gem.files = `git ls-files`.split($/)
28
28
  gem.files = glob[gemspec['files']] if gemspec['files']
29
29
  gem.files += Array(gemspec['generated_files'])
30
+ # exclude test files from the packages gem
31
+ gem.files -= glob[gemspec['test_files'] || 'spec/{**/}*']
30
32
 
31
33
  gem.executables = gemspec.fetch('executables') do
32
34
  glob['bin/*'].map { |path| File.basename(path) }
33
35
  end
34
36
 
35
37
  gem.extensions = glob[gemspec['extensions'] || 'ext/**/extconf.rb']
36
- gem.test_files = glob[gemspec['test_files'] || 'spec/{**/}*_spec.rb']
37
38
  gem.extra_rdoc_files = glob[gemspec['extra_doc_files'] || '*.{txt,md}']
38
39
 
39
40
  gem.require_paths = Array(gemspec.fetch('require_paths') {
@@ -45,7 +46,7 @@ Gem::Specification.new do |gem|
45
46
  gem.required_rubygems_version = gemspec['required_rubygems_version']
46
47
  gem.post_install_message = gemspec['post_install_message']
47
48
 
48
- split = lambda { |string| string.split(/,\s*/) }
49
+ split = ->(string) { string.split(/,\s*/) }
49
50
 
50
51
  if gemspec['dependencies']
51
52
  gemspec['dependencies'].each do |name,versions|
@@ -1,7 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'set'
4
5
 
6
+ #
7
+ # A `User-Agent` strings txt file parser.
8
+ #
5
9
  class UserAgentsFile
6
10
 
7
11
  attr_reader :path
@@ -27,7 +31,7 @@ class UserAgentsFile
27
31
 
28
32
  EXTENSION_SEPARATOR = /\s*;\s+/
29
33
 
30
- REGEXP = /(#{PRODUCT_REGEXP})\/(#{PRODUCT_VERSION_REGEXP})(?:\s+\((#{EXTENSIONS_REGEXP})\))?/
34
+ REGEXP = %r{(#{PRODUCT_REGEXP})/(#{PRODUCT_VERSION_REGEXP})(?:\s+\((#{EXTENSIONS_REGEXP})\))?}
31
35
 
32
36
  VERSION_REGEXP = /\d+(?:\.\d+)*/
33
37
 
@@ -55,7 +59,7 @@ class UserAgentsFile
55
59
  product_versions = Hash.new { |hash,key| hash[key] = 0 }
56
60
 
57
61
  parse do |matches|
58
- _,product_version,_ = *matches.find do |(product,_,_)|
62
+ _, product_version, = *matches.find do |(product,_,_)|
59
63
  product == search_product
60
64
  end
61
65
 
@@ -74,8 +78,6 @@ class UserAgentsFile
74
78
  _,_,extensions = matches.find { |(product,_,_)| product == target_product }
75
79
 
76
80
  if extensions
77
- tree_node = product_extensions
78
-
79
81
  product_extensions[extensions.split(EXTENSION_SEPARATOR)] += 1
80
82
  end
81
83
  end
@@ -115,7 +117,7 @@ class UserAgentsFile
115
117
  each_product('Mozilla') do |product,product_version,extensions|
116
118
  if extensions
117
119
  if (match = extensions.match(/Windows NT (#{VERSION_REGEXP});/))
118
- windows_versions << match[1]
120
+ windows_versions << match[1]
119
121
  end
120
122
  end
121
123
  end
@@ -129,7 +131,7 @@ class UserAgentsFile
129
131
  each_product('Mozilla') do |product,product_version,extensions|
130
132
  if extensions
131
133
  if (match = extensions.match(/; Android (#{VERSION_REGEXP});/))
132
- android_versions << match[1]
134
+ android_versions << match[1]
133
135
  end
134
136
  end
135
137
  end
@@ -199,7 +201,7 @@ if $0 == __FILE__
199
201
  opts.banner = './scripts/index_user_agents [options] FILE'
200
202
 
201
203
  opts.on('--products', 'List all product names') do
202
- @method = :index_product_combinations
204
+ @method = :index_product_combinations
203
205
  @print_mode = :count
204
206
  end
205
207
 
@@ -249,21 +251,21 @@ if $0 == __FILE__
249
251
  args = begin
250
252
  optparser.parse(ARGV)
251
253
  rescue OptionParser::ParseError => error
252
- $stderr.puts "./scripts/index_user_agents: #{error.message}"
253
- exit -1
254
+ warn "./scripts/index_user_agents: #{error.message}"
255
+ exit(-1)
254
256
  end
255
257
 
256
258
  unless (file_path = args[0])
257
- $stderr.puts "./scripts/index_user_agents: must specify a User-Agents FILE"
258
- exit -1
259
+ warn "./scripts/index_user_agents: must specify a User-Agents FILE"
260
+ exit(-1)
259
261
  end
260
262
 
261
263
  user_agents = UserAgentsFile.new(file_path)
262
264
 
263
265
  unless @method
264
- $stderr.puts "./scripts/index_user_agents: must specify atleast one option"
265
- $stderr.puts optparser
266
- exit -1
266
+ warn "./scripts/index_user_agents: must specify atleast one option"
267
+ warn optparser
268
+ exit(-1)
267
269
  end
268
270
 
269
271
  results = user_agents.send(@method,*@method_args)