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, included, native_type, #|, #~

Methods included from Object

#<=>, #cast_to, #copy, #export, #indirect_parent, #is_indirect?, #logicalize, #logicalize!, native_type, #native_type, #pdf, #pdf_version_required, #post_build, #pre_build, #reference, #resolve_all_references, #set_indirect, #set_pdf, #size, skip_until_next_obj, #solve, #to_o, #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.



171
172
173
174
175
176
177
178
# File 'lib/origami/numeric.rb', line 171

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, parser = nil) ⇒ Object

:nodoc:



180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/origami/numeric.rb', line 180

def self.parse(stream, parser = nil) #: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

Instance Method Details

#to_sObject Also known as: to_obfuscated_str



197
198
199
# File 'lib/origami/numeric.rb', line 197

def to_s
  sprintf("%f", self).sub(/\.0*$|(\.\d*[^0])0*$/, '\1')
end