Class: Origami::Real

Inherits:
Float
  • Object
show all
Includes:
Number
Defined in:
lib/origami/numeric.rb,
lib/origami/obfuscation.rb

Overview

Class representing a Real number Object. PDF real numbers are arbitrary precision numbers, depending on architectures.

Constant Summary collapse

TOKENS =

:nodoc:

[ "(\\+|-)?([\\d]*\\.[\\d]+|[\\d]+\\.[\\d]*)([eE](\\+|-)?[\\d]+)?" ]
REGEXP_TOKEN =
Regexp.new(TOKENS.first)
@@regexp =
Regexp.new(WHITESPACES + "(" + TOKENS.first + ")")

Instance Attribute Summary

Attributes included from Object

#file_offset, #generation, #no, #objstm_offset, #parent

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Number

#&, #*, #**, #+, #-, #-@, #/, #<<, #>>, #^, #abs, #real_type, #to_s, #|, #~

Methods included from Object

#<=>, #copy, #indirect_parent, #is_indirect?, #pdf, #pdf_version_required, #post_build, #pre_build, #reference, #set_indirect, #set_pdf, #size, skip_until_next_obj, #solve, #to_o, #to_s, #type, typeof, #xrefs

Methods inherited from Float

#to_o

Constructor Details

#initialize(f = 0) ⇒ Real

Creates a new Real from a Ruby Float.

f

The new Real value.



160
161
162
163
164
165
166
167
# File 'lib/origami/numeric.rb', line 160

def initialize(f = 0)
  
  unless f.is_a?(Float)
    raise TypeError, "Expected type Float, received #{f.class}."
  end
  
  super(f)
end

Class Method Details

.parse(stream) ⇒ Object

:nodoc:



169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/origami/numeric.rb', line 169

def self.parse(stream) #:nodoc:

  offset = stream.pos
  
  if not stream.scan(@@regexp)
    raise InvalidRealObjectError, "Invalid real number format"
  end
   
  value = stream[2].to_f
  real = Real.new(value)
  real.file_offset = offset

  real
end