bidi2pdf 0.1.2 → 0.1.4

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.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +29 -1
  3. data/CHANGELOG.md +36 -0
  4. data/cliff.toml +50 -26
  5. data/docker/Dockerfile.chromedriver +5 -0
  6. data/docker/entrypoint.sh +11 -1
  7. data/docker/nginx/default.conf +6 -0
  8. data/lib/bidi2pdf/bidi/add_headers_interceptor.rb +18 -21
  9. data/lib/bidi2pdf/bidi/auth_interceptor.rb +31 -38
  10. data/lib/bidi2pdf/bidi/browser_tab.rb +32 -52
  11. data/lib/bidi2pdf/bidi/client.rb +30 -57
  12. data/lib/bidi2pdf/bidi/command_manager.rb +50 -28
  13. data/lib/bidi2pdf/bidi/commands/add_intercept.rb +41 -0
  14. data/lib/bidi2pdf/bidi/commands/base.rb +73 -0
  15. data/lib/bidi2pdf/bidi/commands/browser_close.rb +15 -0
  16. data/lib/bidi2pdf/bidi/commands/browser_create_user_context.rb +15 -0
  17. data/lib/bidi2pdf/bidi/commands/browsing_context_close.rb +25 -0
  18. data/lib/bidi2pdf/bidi/commands/browsing_context_navigate.rb +31 -0
  19. data/lib/bidi2pdf/bidi/commands/browsing_context_print.rb +28 -0
  20. data/lib/bidi2pdf/bidi/commands/cancel_auth.rb +26 -0
  21. data/lib/bidi2pdf/bidi/commands/create_tab.rb +11 -0
  22. data/lib/bidi2pdf/bidi/commands/create_window.rb +32 -0
  23. data/lib/bidi2pdf/bidi/commands/get_user_contexts.rb +15 -0
  24. data/lib/bidi2pdf/bidi/commands/network_continue.rb +29 -0
  25. data/lib/bidi2pdf/bidi/commands/print_parameters_validator.rb +116 -0
  26. data/lib/bidi2pdf/bidi/commands/provide_credentials.rb +33 -0
  27. data/lib/bidi2pdf/bidi/commands/script_evaluate.rb +33 -0
  28. data/lib/bidi2pdf/bidi/commands/session_end.rb +15 -0
  29. data/lib/bidi2pdf/bidi/commands/session_status.rb +15 -0
  30. data/lib/bidi2pdf/bidi/commands/session_subscribe.rb +25 -0
  31. data/lib/bidi2pdf/bidi/commands/set_tab_cookie.rb +63 -0
  32. data/lib/bidi2pdf/bidi/commands/set_usercontext_cookie.rb +67 -0
  33. data/lib/bidi2pdf/bidi/commands.rb +27 -0
  34. data/lib/bidi2pdf/bidi/connection_manager.rb +16 -13
  35. data/lib/bidi2pdf/bidi/event_manager.rb +2 -0
  36. data/lib/bidi2pdf/bidi/interceptor.rb +75 -0
  37. data/lib/bidi2pdf/bidi/network_events.rb +0 -1
  38. data/lib/bidi2pdf/bidi/session.rb +141 -76
  39. data/lib/bidi2pdf/bidi/user_context.rb +25 -31
  40. data/lib/bidi2pdf/bidi/web_socket_dispatcher.rb +2 -0
  41. data/lib/bidi2pdf/chromedriver_manager.rb +23 -13
  42. data/lib/bidi2pdf/cli.rb +1 -3
  43. data/lib/bidi2pdf/launcher.rb +3 -1
  44. data/lib/bidi2pdf/version.rb +1 -1
  45. data/lib/bidi2pdf.rb +12 -0
  46. data/sig/bidi2pdf/bidi/command_manager.rbs +41 -0
  47. data/sig/bidi2pdf/bidi/commands/add_intercept.rbs +21 -0
  48. data/sig/bidi2pdf/bidi/commands/base.rbs +27 -0
  49. data/sig/bidi2pdf/bidi/commands/browser_close.rbs +9 -0
  50. data/sig/bidi2pdf/bidi/commands/browser_create_user_context.rbs +9 -0
  51. data/sig/bidi2pdf/bidi/commands/browsing_context_close.rbs +11 -0
  52. data/sig/bidi2pdf/bidi/commands/browsing_context_navigate.rbs +15 -0
  53. data/sig/bidi2pdf/bidi/commands/browsing_context_print.rbs +14 -0
  54. data/sig/bidi2pdf/bidi/commands/cancel_auth.rbs +11 -0
  55. data/sig/bidi2pdf/bidi/commands/create_tab.rbs +9 -0
  56. data/sig/bidi2pdf/bidi/commands/create_window.rbs +19 -0
  57. data/sig/bidi2pdf/bidi/commands/get_user_contexts.rbs +9 -0
  58. data/sig/bidi2pdf/bidi/commands/network_continue.rbs +19 -0
  59. data/sig/bidi2pdf/bidi/commands/print_parameters_validator.rbs +53 -0
  60. data/sig/bidi2pdf/bidi/commands/provide_credentials.rbs +15 -0
  61. data/sig/bidi2pdf/bidi/commands/script_evaluate.rbs +17 -0
  62. data/sig/bidi2pdf/bidi/commands/session_end.rbs +9 -0
  63. data/sig/bidi2pdf/bidi/commands/session_status.rbs +9 -0
  64. data/sig/bidi2pdf/bidi/commands/session_subscribe.rbs +15 -0
  65. data/sig/bidi2pdf/bidi/commands/set_tab_cookie.rbs +31 -0
  66. data/sig/bidi2pdf/bidi/commands/set_usercontext_cookie.rbs +27 -0
  67. data/sig/bidi2pdf/bidi/commands.rbs +6 -0
  68. data/sig/bidi2pdf/bidi/connection_manager.rbs +17 -0
  69. data/sig/bidi2pdf/bidi/interceptor.rbs +31 -0
  70. data/tasks/coverage.rake +16 -0
  71. metadata +65 -11
  72. data/lib/bidi2pdf/bidi/print_parameters_validator.rb +0 -114
  73. data/sig/bidi2pdf/bidi/print_parameters_validator.rbs +0 -44
  74. data/sig/bidi2pdf/chrome/chromedriver_downloader.rbs +0 -11
  75. data/sig/bidi2pdf/chrome/downloader_helper.rbs +0 -9
  76. data/sig/bidi2pdf/chrome/finder.rbs +0 -27
  77. data/sig/bidi2pdf/chrome/platform.rbs +0 -13
  78. data/sig/bidi2pdf/chrome/version_resolver.rbs +0 -19
@@ -0,0 +1,14 @@
1
+ module Bidi2pdf
2
+ module Bidi
3
+ module Commands
4
+ class BrowsingContextPrint
5
+ include Commands::Base
6
+
7
+ def initialize: (
8
+ context: String,
9
+ print_options: Hash[Symbol, untyped]?
10
+ ) -> void
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ module Bidi2pdf
2
+ module Bidi
3
+ module Commands
4
+ class CancelAuth
5
+ include Commands::Base
6
+
7
+ def initialize: (request: String) -> void
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ module Bidi2pdf
2
+ module Bidi
3
+ module Commands
4
+ class CreateTab < CreateWindow
5
+ def type: () -> "tab"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,19 @@
1
+ module Bidi2pdf
2
+ module Bidi
3
+ module Commands
4
+ class CreateWindow
5
+ @user_context_id: untyped
6
+
7
+ @reference_context: untyped
8
+
9
+ @background: untyped
10
+
11
+ include Base
12
+
13
+ def initialize: (?user_context_id: untyped?, ?reference_context: untyped?, ?background: bool) -> void
14
+
15
+ def type: () -> "window"
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,9 @@
1
+ module Bidi2pdf
2
+ module Bidi
3
+ module Commands
4
+ class GetUserContexts
5
+ include Base
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,19 @@
1
+ module Bidi2pdf
2
+ module Bidi
3
+ module Commands
4
+ class NetworkContinue
5
+ @headers: untyped
6
+
7
+ @request: untyped
8
+
9
+ include Base
10
+
11
+ attr_reader request: untyped
12
+
13
+ attr_reader headers: untyped
14
+
15
+ def initialize: (request: untyped, headers: untyped) -> void
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,53 @@
1
+ module Bidi2pdf
2
+ module Bidi
3
+ module Commands
4
+ # Validates parameters for the BiDi method `browsingContext.print`.
5
+ #
6
+ # Allowed structure of the params hash:
7
+ #
8
+ # {
9
+ # background: Boolean (optional, default: false) – print background graphics,
10
+ # margin: {
11
+ # top: Float >= 0.0 (optional, default: 1.0),
12
+ # bottom: Float >= 0.0 (optional, default: 1.0),
13
+ # left: Float >= 0.0 (optional, default: 1.0),
14
+ # right: Float >= 0.0 (optional, default: 1.0)
15
+ # },
16
+ # orientation: "portrait" or "landscape" (optional, default: "portrait"),
17
+ # page: {
18
+ # width: Float >= 0.0352 (optional, default: 21.59),
19
+ # height: Float >= 0.0352 (optional, default: 27.94)
20
+ # },
21
+ # pageRanges: Array of Integers or Strings (optional),
22
+ # scale: Float between 0.1 and 2.0 (optional, default: 1.0),
23
+ # shrinkToFit: Boolean (optional, default: true)
24
+ # }
25
+ #
26
+ # This validator checks presence, types, allowed ranges, and values,
27
+ # and raises ArgumentError with a descriptive message if validation fails.
28
+ class PrintParametersValidator
29
+ @params: untyped
30
+
31
+ def self.validate!: (untyped params) -> untyped
32
+
33
+ def initialize: (untyped params) -> void
34
+
35
+ def validate!: () -> true
36
+
37
+ private
38
+
39
+ def validate_boolean: (untyped key) -> (nil | untyped)
40
+
41
+ def validate_orientation: () -> (nil | untyped)
42
+
43
+ def validate_scale: () -> (nil | untyped)
44
+
45
+ def validate_page_ranges: () -> (nil | untyped)
46
+
47
+ def validate_margin: () -> (nil | untyped)
48
+
49
+ def validate_page_size: () -> (nil | untyped)
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,15 @@
1
+ module Bidi2pdf
2
+ module Bidi
3
+ module Commands
4
+ class ProvideCredentials
5
+ include Commands::Base
6
+
7
+ def initialize: (
8
+ request: String,
9
+ username: String,
10
+ password: String
11
+ ) -> void
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ module Bidi2pdf
2
+ module Bidi
3
+ module Commands
4
+ class ScriptEvaluate
5
+ @expression: untyped
6
+
7
+ @context: untyped
8
+
9
+ @await_promise: untyped
10
+
11
+ include Base
12
+
13
+ def initialize: (expression: untyped, context: untyped, ?await_promise: bool) -> void
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ module Bidi2pdf
2
+ module Bidi
3
+ module Commands
4
+ class SessionEnd
5
+ include Base
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Bidi2pdf
2
+ module Bidi
3
+ module Commands
4
+ class SessionStatus
5
+ include Commands::Base
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ module Bidi2pdf
2
+ module Bidi
3
+ module Commands
4
+ class SessionSubscribe
5
+ @events: untyped
6
+
7
+ include Base
8
+
9
+ attr_reader events: untyped
10
+
11
+ def initialize: (events: untyped) -> void
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,31 @@
1
+ module Bidi2pdf
2
+ module Bidi
3
+ module Commands
4
+ class SetTabCookie
5
+ include Commands::Base
6
+
7
+ attr_reader name: String
8
+ attr_reader value: String
9
+ attr_reader domain: String
10
+ attr_reader path: String
11
+ attr_reader secure: bool
12
+ attr_reader http_only: bool
13
+ attr_reader same_site: String
14
+ attr_reader ttl: Integer
15
+ attr_reader browsing_context_id: String?
16
+
17
+ def initialize: (
18
+ name: String,
19
+ value: String,
20
+ domain: String,
21
+ browsing_context_id: String?,
22
+ ?path: String,
23
+ ?secure: bool,
24
+ ?http_only: bool,
25
+ ?same_site: String,
26
+ ?ttl: Integer
27
+ ) -> void
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,27 @@
1
+ module Bidi2pdf
2
+ module Bidi
3
+ module Commands
4
+ class SetUsercontextCookie < SetTabCookie
5
+ include Commands::Base
6
+
7
+ attr_reader user_context_id: String
8
+ attr_reader source_origin: String
9
+
10
+ def initialize: (
11
+ name: String,
12
+ value: String,
13
+ domain: String,
14
+ user_context_id: String,
15
+ source_origin: String,
16
+ ?path: String,
17
+ ?secure: bool,
18
+ ?http_only: bool,
19
+ ?same_site: String,
20
+ ?ttl: Integer
21
+ ) -> void
22
+
23
+ def expiry: () -> Integer
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,6 @@
1
+ module Bidi2pdf
2
+ module Bidi
3
+ module Commands
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,17 @@
1
+ module Bidi2pdf
2
+ module Bidi
3
+ class ConnectionManager
4
+ @logger: untyped
5
+
6
+ @connected: untyped
7
+
8
+ @connection_queue: untyped
9
+
10
+ def initialize: (logger: untyped) -> void
11
+
12
+ def mark_connected: () -> (nil | untyped)
13
+
14
+ def wait_until_open: (timeout: untyped) -> true
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,31 @@
1
+ module Bidi2pdf
2
+ module Bidi
3
+ module Interceptor
4
+ @client: untyped
5
+
6
+ def self.included: (untyped base) -> untyped
7
+
8
+ module ClassMethods
9
+ def phases: () -> untyped
10
+
11
+ def events: () -> untyped
12
+ end
13
+
14
+ def url_patterns: () -> untyped
15
+
16
+ def context: () -> untyped
17
+
18
+ def process_interception: (untyped _event_response, untyped _navigation_id, untyped _network_id, untyped _url) -> untyped
19
+
20
+ def register_with_client: (client: untyped) -> untyped
21
+
22
+ def handle_event: (untyped response) -> untyped
23
+
24
+ def interceptor_id: () -> untyped
25
+
26
+ def client: () -> untyped
27
+
28
+ def validate_phases!: () -> untyped
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :coverage do
4
+ desc "Merge simplecov coverage reports"
5
+ task :merge_reports do
6
+ require "simplecov"
7
+
8
+ SimpleCov.collate Dir["coverage/*-resultset.json"] do
9
+ formatter SimpleCov::Formatter::MultiFormatter.new([
10
+ SimpleCov::Formatter::SimpleFormatter,
11
+ SimpleCov::Formatter::HTMLFormatter,
12
+ SimpleCov::Formatter::JSONFormatter
13
+ ])
14
+ end
15
+ end
16
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bidi2pdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dieter S.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-04-05 00:00:00.000000000 Z
11
+ date: 2025-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base64
@@ -240,14 +240,28 @@ dependencies:
240
240
  requirements:
241
241
  - - "~>"
242
242
  - !ruby/object:Gem::Version
243
- version: 0.2.0
243
+ version: '0.2'
244
244
  type: :development
245
245
  prerelease: false
246
246
  version_requirements: !ruby/object:Gem::Requirement
247
247
  requirements:
248
248
  - - "~>"
249
249
  - !ruby/object:Gem::Version
250
- version: 0.2.0
250
+ version: '0.2'
251
+ - !ruby/object:Gem::Dependency
252
+ name: testcontainers-nginx
253
+ requirement: !ruby/object:Gem::Requirement
254
+ requirements:
255
+ - - "~>"
256
+ - !ruby/object:Gem::Version
257
+ version: '0.2'
258
+ type: :development
259
+ prerelease: false
260
+ version_requirements: !ruby/object:Gem::Requirement
261
+ requirements:
262
+ - - "~>"
263
+ - !ruby/object:Gem::Version
264
+ version: '0.2'
251
265
  - !ruby/object:Gem::Dependency
252
266
  name: unicode_utils
253
267
  requirement: !ruby/object:Gem::Requirement
@@ -308,11 +322,32 @@ files:
308
322
  - lib/bidi2pdf/bidi/browser_tab.rb
309
323
  - lib/bidi2pdf/bidi/client.rb
310
324
  - lib/bidi2pdf/bidi/command_manager.rb
325
+ - lib/bidi2pdf/bidi/commands.rb
326
+ - lib/bidi2pdf/bidi/commands/add_intercept.rb
327
+ - lib/bidi2pdf/bidi/commands/base.rb
328
+ - lib/bidi2pdf/bidi/commands/browser_close.rb
329
+ - lib/bidi2pdf/bidi/commands/browser_create_user_context.rb
330
+ - lib/bidi2pdf/bidi/commands/browsing_context_close.rb
331
+ - lib/bidi2pdf/bidi/commands/browsing_context_navigate.rb
332
+ - lib/bidi2pdf/bidi/commands/browsing_context_print.rb
333
+ - lib/bidi2pdf/bidi/commands/cancel_auth.rb
334
+ - lib/bidi2pdf/bidi/commands/create_tab.rb
335
+ - lib/bidi2pdf/bidi/commands/create_window.rb
336
+ - lib/bidi2pdf/bidi/commands/get_user_contexts.rb
337
+ - lib/bidi2pdf/bidi/commands/network_continue.rb
338
+ - lib/bidi2pdf/bidi/commands/print_parameters_validator.rb
339
+ - lib/bidi2pdf/bidi/commands/provide_credentials.rb
340
+ - lib/bidi2pdf/bidi/commands/script_evaluate.rb
341
+ - lib/bidi2pdf/bidi/commands/session_end.rb
342
+ - lib/bidi2pdf/bidi/commands/session_status.rb
343
+ - lib/bidi2pdf/bidi/commands/session_subscribe.rb
344
+ - lib/bidi2pdf/bidi/commands/set_tab_cookie.rb
345
+ - lib/bidi2pdf/bidi/commands/set_usercontext_cookie.rb
311
346
  - lib/bidi2pdf/bidi/connection_manager.rb
312
347
  - lib/bidi2pdf/bidi/event_manager.rb
348
+ - lib/bidi2pdf/bidi/interceptor.rb
313
349
  - lib/bidi2pdf/bidi/network_event.rb
314
350
  - lib/bidi2pdf/bidi/network_events.rb
315
- - lib/bidi2pdf/bidi/print_parameters_validator.rb
316
351
  - lib/bidi2pdf/bidi/session.rb
317
352
  - lib/bidi2pdf/bidi/user_context.rb
318
353
  - lib/bidi2pdf/bidi/web_socket_dispatcher.rb
@@ -329,18 +364,36 @@ files:
329
364
  - sig/bidi2pdf/bidi/browser.rbs
330
365
  - sig/bidi2pdf/bidi/browser_tab.rbs
331
366
  - sig/bidi2pdf/bidi/client.rbs
367
+ - sig/bidi2pdf/bidi/command_manager.rbs
368
+ - sig/bidi2pdf/bidi/commands.rbs
369
+ - sig/bidi2pdf/bidi/commands/add_intercept.rbs
370
+ - sig/bidi2pdf/bidi/commands/base.rbs
371
+ - sig/bidi2pdf/bidi/commands/browser_close.rbs
372
+ - sig/bidi2pdf/bidi/commands/browser_create_user_context.rbs
373
+ - sig/bidi2pdf/bidi/commands/browsing_context_close.rbs
374
+ - sig/bidi2pdf/bidi/commands/browsing_context_navigate.rbs
375
+ - sig/bidi2pdf/bidi/commands/browsing_context_print.rbs
376
+ - sig/bidi2pdf/bidi/commands/cancel_auth.rbs
377
+ - sig/bidi2pdf/bidi/commands/create_tab.rbs
378
+ - sig/bidi2pdf/bidi/commands/create_window.rbs
379
+ - sig/bidi2pdf/bidi/commands/get_user_contexts.rbs
380
+ - sig/bidi2pdf/bidi/commands/network_continue.rbs
381
+ - sig/bidi2pdf/bidi/commands/print_parameters_validator.rbs
382
+ - sig/bidi2pdf/bidi/commands/provide_credentials.rbs
383
+ - sig/bidi2pdf/bidi/commands/script_evaluate.rbs
384
+ - sig/bidi2pdf/bidi/commands/session_end.rbs
385
+ - sig/bidi2pdf/bidi/commands/session_status.rbs
386
+ - sig/bidi2pdf/bidi/commands/session_subscribe.rbs
387
+ - sig/bidi2pdf/bidi/commands/set_tab_cookie.rbs
388
+ - sig/bidi2pdf/bidi/commands/set_usercontext_cookie.rbs
389
+ - sig/bidi2pdf/bidi/connection_manager.rbs
332
390
  - sig/bidi2pdf/bidi/event_manager.rbs
391
+ - sig/bidi2pdf/bidi/interceptor.rbs
333
392
  - sig/bidi2pdf/bidi/network_event.rbs
334
393
  - sig/bidi2pdf/bidi/network_events.rbs
335
- - sig/bidi2pdf/bidi/print_parameters_validator.rbs
336
394
  - sig/bidi2pdf/bidi/session.rbs
337
395
  - sig/bidi2pdf/bidi/user_context.rbs
338
396
  - sig/bidi2pdf/bidi/web_socket_dispatcher.rbs
339
- - sig/bidi2pdf/chrome/chromedriver_downloader.rbs
340
- - sig/bidi2pdf/chrome/downloader_helper.rbs
341
- - sig/bidi2pdf/chrome/finder.rbs
342
- - sig/bidi2pdf/chrome/platform.rbs
343
- - sig/bidi2pdf/chrome/version_resolver.rbs
344
397
  - sig/bidi2pdf/chromedriver_manager.rbs
345
398
  - sig/bidi2pdf/cli.rbs
346
399
  - sig/bidi2pdf/launcher.rbs
@@ -349,6 +402,7 @@ files:
349
402
  - sig/bidi2pdf/utils.rbs
350
403
  - sig/vendor/thor.rbs
351
404
  - tasks/changelog.rake
405
+ - tasks/coverage.rake
352
406
  - tasks/generate_rbs.rake
353
407
  - tmp/.keep
354
408
  homepage: https://github.com/dieter-medium/bidi2pdf
@@ -1,114 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Bidi2pdf
4
- module Bidi
5
- # Validates parameters for the BiDi method `browsingContext.print`.
6
- #
7
- # Allowed structure of the params hash:
8
- #
9
- # {
10
- # background: Boolean (optional, default: false) – print background graphics,
11
- # margin: {
12
- # top: Float >= 0.0 (optional, default: 1.0),
13
- # bottom: Float >= 0.0 (optional, default: 1.0),
14
- # left: Float >= 0.0 (optional, default: 1.0),
15
- # right: Float >= 0.0 (optional, default: 1.0)
16
- # },
17
- # orientation: "portrait" or "landscape" (optional, default: "portrait"),
18
- # page: {
19
- # width: Float >= 0.0352 (optional, default: 21.59),
20
- # height: Float >= 0.0352 (optional, default: 27.94)
21
- # },
22
- # pageRanges: Array of Integers or Strings (optional),
23
- # scale: Float between 0.1 and 2.0 (optional, default: 1.0),
24
- # shrinkToFit: Boolean (optional, default: true)
25
- # }
26
- #
27
- # This validator checks presence, types, allowed ranges, and values,
28
- # and raises ArgumentError with a descriptive message if validation fails.
29
- class PrintParametersValidator
30
- def self.validate!(params)
31
- new(params).validate!
32
- end
33
-
34
- def initialize(params)
35
- @params = params
36
- end
37
-
38
- def validate!
39
- raise ArgumentError, "params must be a Hash" unless @params.is_a?(Hash)
40
-
41
- validate_boolean(:background)
42
- validate_boolean(:shrinkToFit)
43
- validate_orientation
44
- validate_scale
45
- validate_page_ranges
46
- validate_margin
47
- validate_page_size
48
-
49
- true
50
- end
51
-
52
- private
53
-
54
- def validate_boolean(key)
55
- return unless @params.key?(key)
56
- return if [true, false].include?(@params[key])
57
-
58
- raise ArgumentError, ":#{key} must be a boolean"
59
- end
60
-
61
- def validate_orientation
62
- return unless @params.key?(:orientation)
63
- return if %w[portrait landscape].include?(@params[:orientation])
64
-
65
- raise ArgumentError, ":orientation must be 'portrait' or 'landscape'"
66
- end
67
-
68
- def validate_scale
69
- return unless @params.key?(:scale)
70
-
71
- scale = @params[:scale]
72
- return if scale.is_a?(Numeric) && scale >= 0.1 && scale <= 2.0
73
-
74
- raise ArgumentError, ":scale must be a number between 0.1 and 2.0"
75
- end
76
-
77
- def validate_page_ranges
78
- return unless @params.key?(:pageRanges)
79
- unless @params[:pageRanges].is_a?(Array) &&
80
- @params[:pageRanges].all? { |v| v.is_a?(Integer) || v.is_a?(String) }
81
- raise ArgumentError, ":pageRanges must be an array of integers or strings"
82
- end
83
- end
84
-
85
- def validate_margin
86
- return unless @params.key?(:margin)
87
-
88
- margin = @params[:margin]
89
- raise ArgumentError, ":margin must be a Hash" unless margin.is_a?(Hash)
90
-
91
- %i[top bottom left right].each do |side|
92
- next unless margin.key?(side)
93
-
94
- val = margin[side]
95
- raise ArgumentError, "margin[:#{side}] must be a float >= 0.0" unless val.is_a?(Numeric) && val >= 0.0
96
- end
97
- end
98
-
99
- def validate_page_size
100
- return unless @params.key?(:page)
101
-
102
- page = @params[:page]
103
- raise ArgumentError, ":page must be a Hash" unless page.is_a?(Hash)
104
-
105
- %i[width height].each do |dim|
106
- next unless page.key?(dim)
107
-
108
- val = page[dim]
109
- raise ArgumentError, "page[:#{dim}] must be a float >= 0.0352" unless val.is_a?(Numeric) && val >= 0.0352
110
- end
111
- end
112
- end
113
- end
114
- end
@@ -1,44 +0,0 @@
1
- module Bidi2pdf
2
- module Bidi
3
- class PrintParametersValidator
4
- # Valid print parameter configurations
5
- DEFAULT_PARAMETERS: Hash[Symbol, untyped]
6
- ALLOWED_PAGE_RANGES_FORMATS: Array[String]
7
- ALLOWED_MARGIN_UNITS: Array[String]
8
- ALLOWED_PAPER_FORMATS: Array[String]
9
- ALLOWED_ORIENTATIONS: Array[String]
10
-
11
- @parameters: Hash[Symbol, untyped]
12
- @errors: Array[String]
13
-
14
- attr_reader errors: Array[String]
15
- attr_reader parameters: Hash[Symbol, untyped]
16
-
17
- def initialize: (Hash[Symbol, untyped] parameters) -> void
18
-
19
- def validate: () -> bool
20
-
21
- def valid?: () -> bool
22
-
23
- private
24
-
25
- def validate_boolean: (Symbol key) -> void
26
-
27
- def validate_number: (Symbol key, ?min: Numeric?, ?max: Numeric?) -> void
28
-
29
- def validate_string: (Symbol key) -> void
30
-
31
- def validate_enum: (Symbol key, Array[String] allowed_values) -> void
32
-
33
- def validate_margins: () -> void
34
-
35
- def validate_page_ranges: () -> void
36
-
37
- def validate_paper_size: () -> void
38
-
39
- def normalize_parameters: () -> void
40
-
41
- def add_error: (String message) -> void
42
- end
43
- end
44
- end
@@ -1,11 +0,0 @@
1
- module Bidi2pdf
2
- module Chrome
3
- class ChromedriverDownloader
4
- def self.install_dir: -> String
5
-
6
- def self.target: -> String
7
-
8
- def self.update: -> String
9
- end
10
- end
11
- end
@@ -1,9 +0,0 @@
1
- module Bidi2pdf
2
- module Chrome
3
- module DownloaderHelper
4
- def download_file: (String url, String destination) -> nil
5
-
6
- def extract_zip: (String zip_file, String destination) -> nil
7
- end
8
- end
9
- end