Class: Origami::Integer

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

Overview

Class representing an Integer Object.

Constant Summary collapse

TOKENS =

:nodoc:

["(\\+|-)?[\\d]+[^.]?"]
REGEXP_TOKEN =
Regexp.new(TOKENS.first)
@@regexp =
Regexp.new(WHITESPACES + "(?<int>(\\+|-)?[\\d]+)")

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

Methods included from Object

#cast_to, #copy, #document, #export, included, #indirect?, #indirect_parent, #logicalize, #logicalize!, #native_type, #numbered?, #post_build, #pre_build, #reference, #set_document, #set_indirect, skip_until_next_obj, #solve, #to_o, #type, typeof, #version_required, #xrefs

Constructor Details

#initialize(i = 0) ⇒ Integer

Creates a new Integer from a Ruby Fixnum / Bignum.

i

The Integer value.



101
102
103
104
105
106
107
# File 'lib/origami/numeric.rb', line 101

def initialize(i = 0)
  unless i.is_a?(::Integer)
    raise TypeError, "Expected type Fixnum or Bignum, received #{i.class}."
  end

  super
end

Class Method Details

.parse(stream, _parser = nil) ⇒ Object

:nodoc:



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

def self.parse(stream, _parser = nil) # :nodoc:
  scanner = Parser.init_scanner(stream)
  offset = scanner.pos

  if !scanner.scan(@@regexp)
    raise InvalidIntegerObjectError, "Invalid integer format"
  end

  value = scanner['int'].to_i
  int = Integer.new(value)
  int.file_offset = offset

  int
end

Instance Method Details

#to_s(eol: $/) ⇒ Object Also known as: to_obfuscated_str

:nodoc:



124
125
126
# File 'lib/origami/numeric.rb', line 124

def to_s(eol: $/) # :nodoc:
  super(value.to_s, eol: eol)
end