Class: Origami::Boolean

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

Overview

Class representing a Boolean Object. A Boolean Object can be true or false.

Constant Summary collapse

TOKENS =

:nodoc:

%w{ true false }
@@regexp =
Regexp.new(WHITESPACES + "(?<value>#{Regexp.union(TOKENS)})")

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 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(value) ⇒ Boolean

Creates a new Boolean value.

value

true or false.



40
41
42
43
44
45
46
47
48
# File 'lib/origami/boolean.rb', line 40

def initialize(value)
    unless value.is_a?(TrueClass) or value.is_a?(FalseClass)
        raise TypeError, "Expected type TrueClass or FalseClass, received #{value.class}."
    end

    super()

    @value = (value == true)
end

Class Method Details

.parse(stream, _parser = nil) ⇒ Object

:nodoc:



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/origami/boolean.rb', line 54

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

    if scanner.scan(@@regexp).nil?
        raise InvalidBooleanObjectError
    end

    value = (scanner['value'] == "true")

    bool = Boolean.new(value)
    bool.file_offset = offset

    bool
end

Instance Method Details

#==(bool) ⇒ Object



85
86
87
# File 'lib/origami/boolean.rb', line 85

def ==(bool)
    @value == bool
end

#false?Boolean

Returns:



77
78
79
# File 'lib/origami/boolean.rb', line 77

def false?
    @value == false
end

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

:nodoc:



50
51
52
# File 'lib/origami/boolean.rb', line 50

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

#true?Boolean

Returns:



81
82
83
# File 'lib/origami/boolean.rb', line 81

def true?
    @value == true
end

#valueObject

Converts self into a Ruby boolean, that is TrueClass or FalseClass instance.



73
74
75
# File 'lib/origami/boolean.rb', line 73

def value
    @value
end