Class: Factorix::SerDes::SignedInteger

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/factorix/ser_des/signed_integer.rb,
sig/factorix/ser_des/signed_integer.rbs

Overview

Signed integer wrapper

This class wraps an Integer value to indicate it was originally stored as a signed integer (Type 6) in Factorio's Property Tree format.

Examples:

Creating a signed integer

value = SignedInteger.new(42)
value + 1  # => 43 (behaves like Integer)

Negative values are allowed

value = SignedInteger.new(-5)

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ SignedInteger

Create a new SignedInteger

Parameters:

  • value (Integer) —

    The integer value

Raises:

  • (ArgumentError) —

    If value is not an Integer



23
24
25
26
27
# File 'lib/factorix/ser_des/signed_integer.rb', line 23

def initialize(value)
  raise ArgumentError, "value must be an Integer" unless value.is_a?(Integer)

  super
end

Instance Method Details

#% ⇒ Numeric

Parameters:

  • other (Numeric)

Returns:

  • (Numeric)


25
# File 'sig/factorix/ser_des/signed_integer.rbs', line 25

def %: (Numeric other) -> Numeric

#* ⇒ Numeric

Parameters:

  • other (Numeric)

Returns:

  • (Numeric)


23
# File 'sig/factorix/ser_des/signed_integer.rbs', line 23

def *: (Numeric other) -> Numeric

#** ⇒ Numeric

Parameters:

  • other (Numeric)

Returns:

  • (Numeric)


26
# File 'sig/factorix/ser_des/signed_integer.rbs', line 26

def **: (Numeric other) -> Numeric

#+ ⇒ Numeric

Delegated Integer methods

Parameters:

  • other (Numeric)

Returns:

  • (Numeric)


21
# File 'sig/factorix/ser_des/signed_integer.rbs', line 21

def +: (Numeric other) -> Numeric

#- ⇒ Numeric

Parameters:

  • other (Numeric)

Returns:

  • (Numeric)


22
# File 'sig/factorix/ser_des/signed_integer.rbs', line 22

def -: (Numeric other) -> Numeric

#/ ⇒ Numeric

Parameters:

  • other (Numeric)

Returns:

  • (Numeric)


24
# File 'sig/factorix/ser_des/signed_integer.rbs', line 24

def /: (Numeric other) -> Numeric

#< ⇒ Boolean

Parameters:

  • other (Numeric)

Returns:

  • (Boolean)


28
# File 'sig/factorix/ser_des/signed_integer.rbs', line 28

def <: (Numeric other) -> bool

#<= ⇒ Boolean

Parameters:

  • other (Numeric)

Returns:

  • (Boolean)


29
# File 'sig/factorix/ser_des/signed_integer.rbs', line 29

def <=: (Numeric other) -> bool

#<=> ⇒ Integer?

Parameters:

  • other (Object)

Returns:

  • (Integer, nil)


27
# File 'sig/factorix/ser_des/signed_integer.rbs', line 27

def <=>: (untyped other) -> Integer?

#==(other) ⇒ Boolean Also known as: eql?

Compare with another SignedInteger or Integer

Parameters:

Returns:

  • (Boolean) —

    True if equal



38
39
40
41
42
43
44
45
46
47
# File 'lib/factorix/ser_des/signed_integer.rb', line 38

def ==(other)
  case other
  when SignedInteger
    value == other.value
  when Integer
    value == other
  else
    false
  end
end

#> ⇒ Boolean

Parameters:

  • other (Numeric)

Returns:

  • (Boolean)


30
# File 'sig/factorix/ser_des/signed_integer.rbs', line 30

def >: (Numeric other) -> bool

#>= ⇒ Boolean

Parameters:

  • other (Numeric)

Returns:

  • (Boolean)


31
# File 'sig/factorix/ser_des/signed_integer.rbs', line 31

def >=: (Numeric other) -> bool

#hash ⇒ Integer

Hash code for use in Hash keys

Returns:

  • (Integer) —

    Hash code



52
# File 'lib/factorix/ser_des/signed_integer.rb', line 52

def hash = [value, :signed].hash

#inspect ⇒ String

String representation

Returns:

  • (String) —

    String representation



60
# File 'lib/factorix/ser_des/signed_integer.rb', line 60

def inspect = "#<Factorix::SerDes::SignedInteger:0x%016x value=#{value}>" % object_id

#to_f ⇒ Float

Returns:

  • (Float)


34
# File 'sig/factorix/ser_des/signed_integer.rbs', line 34

def to_f: () -> Float

#to_i ⇒ Integer

Returns:

  • (Integer)


33
# File 'sig/factorix/ser_des/signed_integer.rbs', line 33

def to_i: () -> Integer

#to_s ⇒ String

Returns:

  • (String)


32
# File 'sig/factorix/ser_des/signed_integer.rbs', line 32

def to_s: () -> String

#value ⇒ Integer

Get the underlying integer value

Returns:

  • (Integer) —

    The wrapped integer value



32
# File 'lib/factorix/ser_des/signed_integer.rb', line 32

def value = __getobj__