Class: Bidi2pdf::Bidi::Commands::PrintParametersValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/bidi2pdf/bidi/commands/print_parameters_validator.rb

Overview

Validates parameters for the BiDi method browsingContext.print.

Allowed structure of the params hash:

{ background: Boolean (optional, default: false) – print background graphics, margin: { top: Float >= 0.0 (optional, default: 1.0), bottom: Float >= 0.0 (optional, default: 1.0), left: Float >= 0.0 (optional, default: 1.0), right: Float >= 0.0 (optional, default: 1.0) }, orientation: "portrait" or "landscape" (optional, default: "portrait"), page: { format: String (optional, use either format or width/height), width: Float >= 0.0352 (optional, default: 21.59), height: Float >= 0.0352 (optional, default: 27.94) }, pageRanges: Array of Integers or Strings (optional), scale: Float between 0.1 and 2.0 (optional, default: 1.0), shrinkToFit: Boolean (optional, default: true) }

This validator checks presence, types, allowed ranges, and values, and raises ArgumentError with a descriptive message if validation fails.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ PrintParametersValidator

Returns a new instance of PrintParametersValidator.



36
37
38
# File 'lib/bidi2pdf/bidi/commands/print_parameters_validator.rb', line 36

def initialize(params)
  @params = params
end

Class Method Details

.validate!(params) ⇒ Object



32
33
34
# File 'lib/bidi2pdf/bidi/commands/print_parameters_validator.rb', line 32

def self.validate!(params)
  new(params).validate!
end

Instance Method Details

#validate!Object

rubocop:disable Naming/PredicateMethod

Raises:



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/bidi2pdf/bidi/commands/print_parameters_validator.rb', line 41

def validate!
  raise ArgumentError, "params must be a Hash" unless @params.is_a?(Hash)

  validate_boolean(:background)
  validate_boolean(:shrinkToFit)
  validate_orientation
  validate_scale
  validate_page_ranges
  validate_margin
  validate_page_size

  true
end