Module: Bidi2pdf

Defined in:
lib/bidi2pdf/bidi/session.rb,
lib/bidi2pdf.rb,
lib/bidi2pdf/cli.rb,
lib/bidi2pdf/dsl.rb,
lib/bidi2pdf/version.rb,
lib/bidi2pdf/launcher.rb,
lib/bidi2pdf/bidi/client.rb,
lib/bidi2pdf/bidi/browser.rb,
lib/bidi2pdf/process_tree.rb,
lib/bidi2pdf/bidi/commands.rb,
lib/bidi2pdf/notifications.rb,
lib/bidi2pdf/session_runner.rb,
lib/bidi2pdf/verbose_logger.rb,
lib/bidi2pdf/bidi/browser_tab.rb,
lib/bidi2pdf/bidi/interceptor.rb,
lib/bidi2pdf/bidi/user_context.rb,
lib/bidi2pdf/bidi/commands/base.rb,
lib/bidi2pdf/bidi/event_manager.rb,
lib/bidi2pdf/bidi/logger_events.rb,
lib/bidi2pdf/bidi/network_event.rb,
lib/bidi2pdf/bidi/network_events.rb,
lib/bidi2pdf/notifications/event.rb,
lib/bidi2pdf/bidi/command_manager.rb,
lib/bidi2pdf/chromedriver_manager.rb,
lib/bidi2pdf/bidi/auth_interceptor.rb,
lib/bidi2pdf/bidi/js_logger_helper.rb,
lib/bidi2pdf/bidi/connection_manager.rb,
lib/bidi2pdf/bidi/commands/create_tab.rb,
lib/bidi2pdf/bidi/commands/page_print.rb,
lib/bidi2pdf/bidi/commands/cancel_auth.rb,
lib/bidi2pdf/bidi/commands/session_end.rb,
lib/bidi2pdf/bidi/web_socket_dispatcher.rb,
lib/bidi2pdf/notifications/instrumenter.rb,
lib/bidi2pdf/test_helpers/configuration.rb,
lib/bidi2pdf/bidi/browser_console_logger.rb,
lib/bidi2pdf/bidi/commands/add_intercept.rb,
lib/bidi2pdf/bidi/commands/browser_close.rb,
lib/bidi2pdf/bidi/commands/create_window.rb,
lib/bidi2pdf/test_helpers/testcontainers.rb,
lib/bidi2pdf/bidi/add_headers_interceptor.rb,
lib/bidi2pdf/bidi/commands/session_status.rb,
lib/bidi2pdf/bidi/commands/set_tab_cookie.rb,
lib/bidi2pdf/test_helpers/pdf_file_helper.rb,
lib/bidi2pdf/bidi/commands/cdp_get_session.rb,
lib/bidi2pdf/bidi/commands/script_evaluate.rb,
lib/bidi2pdf/bidi/navigation_failed_events.rb,
lib/bidi2pdf/bidi/network_event_formatters.rb,
lib/bidi2pdf/test_helpers/images/extractor.rb,
lib/bidi2pdf/test_helpers/pdf_reader_utils.rb,
lib/bidi2pdf/bidi/commands/network_continue.rb,
lib/bidi2pdf/test_helpers/spec_paths_helper.rb,
lib/bidi2pdf/bidi/commands/get_user_contexts.rb,
lib/bidi2pdf/bidi/commands/session_subscribe.rb,
lib/bidi2pdf/test_helpers/images/tiff_helper.rb,
lib/bidi2pdf/test_helpers/pdf_text_sanitizer.rb,
lib/bidi2pdf/notifications/logging_subscriber.rb,
lib/bidi2pdf/bidi/commands/provide_credentials.rb,
lib/bidi2pdf/bidi/commands/browsing_context_close.rb,
lib/bidi2pdf/bidi/commands/browsing_context_print.rb,
lib/bidi2pdf/bidi/commands/set_usercontext_cookie.rb,
lib/bidi2pdf/bidi/commands/browsing_context_navigate.rb,
lib/bidi2pdf/bidi/commands/print_parameters_validator.rb,
lib/bidi2pdf/bidi/commands/browser_create_user_context.rb,
lib/bidi2pdf/bidi/commands/browser_remove_user_context.rb,
lib/bidi2pdf/test_helpers/images/image_similarity_checker.rb,
lib/bidi2pdf/test_helpers/testcontainers/chromedriver_container.rb,
lib/bidi2pdf/test_helpers/testcontainers/chromedriver_test_helper.rb,
lib/bidi2pdf/test_helpers/testcontainers/testcontainers_refinement.rb,
lib/bidi2pdf/bidi/network_event_formatters/network_event_html_formatter.rb,
lib/bidi2pdf/bidi/network_event_formatters/network_event_formatter_utils.rb,
lib/bidi2pdf/bidi/network_event_formatters/network_event_console_formatter.rb

Overview

This module provides helper methods for managing paths in test environments. It includes methods to retrieve directories and generate temporary file paths.

Defined Under Namespace

Modules: Bidi, DSL, Notifications, TestHelpers Classes: CLI, ChromedriverManager, ClientError, CmdError, CmdResponseNotStoredError, CmdTimeoutError, Error, Launcher, NavigationAuthError, NavigationDNSError, NavigationError, NavigationNotFoundError, NavigationTimeoutError, NotificationsError, PrintError, ProcessTree, ScriptInjectionError, SessionNotStartedError, SessionRunner, StyleInjectionError, VerboseLogger, WebsocketError

Constant Summary collapse

PAPER_FORMATS_CM =
{
  letter: { width: 21.59, height: 27.94 },
  legal: { width: 21.59, height: 35.56 },
  tabloid: { width: 27.94, height: 43.18 },
  ledger: { width: 43.18, height: 27.94 },
  a0: { width: 84.1, height: 118.9 },
  a1: { width: 59.4, height: 84.1 },
  a2: { width: 42.0, height: 59.4 },
  a3: { width: 29.7, height: 42.0 },
  a4: { width: 21.0, height: 29.7 },
  a5: { width: 14.8, height: 21.0 },
  a6: { width: 10.5, height: 14.8 }
}.freeze
VERSION =
"0.1.12"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.browser_console_loggerObject

Returns the value of attribute browser_console_logger.



89
90
91
# File 'lib/bidi2pdf.rb', line 89

def browser_console_logger
  @browser_console_logger
end

.default_timeoutObject

Returns the value of attribute default_timeout.



88
89
90
# File 'lib/bidi2pdf.rb', line 88

def default_timeout
  @default_timeout
end

.enable_default_logging_subscriberObject

Returns the value of attribute enable_default_logging_subscriber.



88
89
90
# File 'lib/bidi2pdf.rb', line 88

def enable_default_logging_subscriber
  @enable_default_logging_subscriber
end

.loggerObject

Returns the value of attribute logger.



89
90
91
# File 'lib/bidi2pdf.rb', line 89

def logger
  @logger
end

.logging_subscriberObject

Returns the value of attribute logging_subscriber.



89
90
91
# File 'lib/bidi2pdf.rb', line 89

def logging_subscriber
  @logging_subscriber
end

.network_events_loggerObject

Returns the value of attribute network_events_logger.



89
90
91
# File 'lib/bidi2pdf.rb', line 89

def network_events_logger
  @network_events_logger
end

.notification_serviceObject

Returns the value of attribute notification_service.



89
90
91
# File 'lib/bidi2pdf.rb', line 89

def notification_service
  @notification_service
end

Class Method Details

.configure {|_self| ... } ⇒ Object

Allow configuration through a block

Yields:

  • (_self)

Yield Parameters:

  • _self (Bidi2pdf)

    the object that the method was called on



92
93
94
95
96
# File 'lib/bidi2pdf.rb', line 92

def configure
  yield self if block_given?

  init
end

.initObject



98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/bidi2pdf.rb', line 98

def init
  self.logging_subscriber = (Notifications::LoggingSubscriber.new(logger: logger) if enable_default_logging_subscriber)
  begin
    require "websocket-native"

    logger.debug "websocket-native available; use enhance performance."
  rescue LoadError => e
    raise unless e.message =~ /websocket-native/

    logger.warn "websocket-native not available; installing it may enhance performance."
  end
end

.translate_paper_format(format) ⇒ Object

Raises:

  • (ArgumentError)


111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/bidi2pdf.rb', line 111

def translate_paper_format(format)
  format = format.to_s.downcase.to_sym

  dim = PAPER_FORMATS_CM[format]

  raise ArgumentError, "Invalid paper format: #{format}" unless dim

  width = dim[:width] || 0
  height = dim[:height] || 0

  { width: width, height: height }
end