Class: RetroIDL::ASN::EnumerationItem

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

Overview

An item within an ENUMERATED type

X.680 section 20

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**opts) ⇒ EnumerationItem

Returns a new instance of EnumerationItem.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/retro_idl/asn/enumeration_item.rb', line 26

def initialize(**opts)

    @id = opts[:id].to_s
    @location = opts[:location]                
    @mod = nil
    @symbol = nil
    @number = nil
    
    if RetroIDL::ASN.is_identifier?(@location, @id)
        if opts[:number]
            if opts[:number].is_a? String
                @symbol = opts[:number].to_s            
            else
                @number = opts[:number].to_i
            end
        end
    else
        raise ASNError
    end                

end

Instance Attribute Details

#locationHash (readonly)

Returns location record.

Returns:

  • (Hash)

    location record



49
50
51
# File 'lib/retro_idl/asn/enumeration_item.rb', line 49

def location
  @location
end

Instance Method Details

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



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/retro_idl/asn/enumeration_item.rb', line 52

def link(mod, stack)

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

        @mod = nil

        if @symbol

            if mod.symbols(@symbol)

                @mod = mod

            else

                ASN.putError(@location, SYMBOL_UNDEFINED_ERROR)

            end

        else

            @mod = mod

        end

    end

    @mod

end

#to_sString

Convert object to ASN.1 syntax representation

Returns:

  • (String)

    ASN.1 syntax representation

Raises:



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/retro_idl/asn/enumeration_item.rb', line 83

def to_s

    if @symbol

        "#{@id} (#{@symbol})"

    elsif @number

        "#{@id} (#{@number})"

    else

        "#{@id}"

    end

end