Class: RetroIDL::ASN::INTEGER

Inherits:
BaseType
  • Object
show all
Defined in:
lib/retro_idl/asn/integer.rb

Overview

X.680 section 19

Constant Summary collapse

TAG_CLASS_NUMBER =
2
TAG_CLASS =
:universal

Instance Attribute Summary

Attributes inherited from BaseType

#id

Instance Method Summary collapse

Methods inherited from BaseType

===

Constructor Details

#initialize(**opts) ⇒ INTEGER

Returns a new instance of INTEGER.

Parameters:

  • opts (Hash)

Options Hash (**opts):

  • :numberList (Array<Hash>)

    NamedNumberList

Raises:

See Also:



35
36
37
38
39
40
41
# File 'lib/retro_idl/asn/integer.rb', line 35

def initialize(**opts)
    super(**opts)
    @numberList = nil
    if opts[:numberList]
        @numberList = ValueList.new(opts[:numberList], NamedNumber)
    end
end

Instance Method Details

#evaluate(value) ⇒ TrueClass, FalseClass

Note:

may be called before linking but will raise exception if references to not resolve

evaluate a native Ruby value against a type definition

Parameters:

  • value (String, Numeric)

    value to test against type definition

Returns:

  • (TrueClass)

    value fits type definition

  • (FalseClass)

    value does not fit type definition

Raises:

  • (ASNError)

    cannot evaluate against unresolved references



74
75
76
# File 'lib/retro_idl/asn/integer.rb', line 74

def evaluate(value)
    value.kind_of?(Integer)
end

#evaluateConstraint(value) ⇒ Object



78
79
80
81
82
# File 'lib/retro_idl/asn/integer.rb', line 78

def evaluateConstraint(value)
    if evaluate(value) and ( @constrant.nil? or @constraint.evaluate(value) )
        true
    end
end

resolve symbols to definitions in module

Parameters:

  • mod (MODULE)

    module this type belongs to

  • stack (Array)

    objects called before this object for depth first search of recursion

Returns:

  • (MODULE)

    object has been linked

  • (nil)

    object has not been linked



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/retro_idl/asn/integer.rb', line 44

def link(mod, stack)

    if @mod.nil? or @mod != mod

        @mod = nil

        if @numberList.nil? or @numberList.link(mod, [])

            super(mod, stack)

        end

    end

    @mod

end

#to_sString

Convert object to ASN.1 syntax representation

Returns:

  • (String)

    ASN.1 syntax representation

Raises:



63
64
65
66
67
68
69
70
71
# File 'lib/retro_idl/asn/integer.rb', line 63

def to_s

    result = "#{@tag} INTEGER"
    if @numberList
        result << @numberList.to_s
    end
    result << " #{@constraint}"

end