Class: HexaPDF::Content::Operator::BaseOperator

Inherits:
Object
  • Object
show all
Defined in:
lib/hexapdf/content/operator.rb

Overview

Base class for operator implementations.

A default implementation for the #serialize method is provided. However, for performance reasons each operator should provide a custom #serialize method.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ BaseOperator

Initialize the operator called name.



90
91
92
# File 'lib/hexapdf/content/operator.rb', line 90

def initialize(name)
  @name = name.freeze
end

Instance Attribute Details

#nameObject (readonly)

The name of the operator.



87
88
89
# File 'lib/hexapdf/content/operator.rb', line 87

def name
  @name
end

Instance Method Details

#invokeObject

Invokes the operator so that it performs its job.

This base version does nothing!



97
98
# File 'lib/hexapdf/content/operator.rb', line 97

def invoke(*)
end

#serialize(serializer, *operands) ⇒ Object

Returns the string representation of the operator, i.e.

operand1 operand2 operand3 name


103
104
105
106
107
108
109
# File 'lib/hexapdf/content/operator.rb', line 103

def serialize(serializer, *operands)
  result = ''.b
  operands.each do |operand|
    result << serializer.serialize(operand) << " "
  end
  result << name << "\n"
end