Class: SlowBlink::Message::DynamicGroup

Inherits:
Object
  • Object
show all
Defined in:
lib/slow_blink/message/dynamic_group.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ DynamicGroup

Note:

calls #set(value)

Returns a new instance of DynamicGroup.



112
113
114
# File 'lib/slow_blink/message/dynamic_group.rb', line 112

def initialize(value)
    set(value)
end

Class Method Details

.from_compact(input, depth) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/slow_blink/message/dynamic_group.rb', line 34

def self.from_compact(input, depth)

    group = nil

    if depth > 0
        depth = depth - 1
    else
        raise RecursionLimit
    end

    if input.kind_of? String
        input = StringIO.new(input)
    end

    buf = input.getBinary

    if buf.nil?

        group = nil

    elsif buf.size == 0

        raise WeakError5.new "W5: Value cannot be null"                

    else

        buf = StringIO.new(buf)
        id = buf.getU64

        if klass = @taggedGroups[id]

            if @permittedID.include? id

                group = klass.from_compact(buf, depth)

                if !buf.eof?                
                    size = buf.getU32
                    while group.extension.size < size do
                        group.extension << @anyTaggedGroup.from_compact(buf, depth).get
                    end
                end

                if !buf.eof?
                    raise ExtensionPadding
                end
                
            else
                raise WeakError15.new "W15: Group is known but unexpected"
            end
        else
            raise WeakError2.new "W2: Group id #{id} is unknown"
        end                   
        
    end

    depth = depth + 1
    self.new(group)

end

.permittedIDObject



30
31
32
# File 'lib/slow_blink/message/dynamic_group.rb', line 30

def self.permittedID
    @permittedID
end

.taggedGroupsObject



26
27
28
# File 'lib/slow_blink/message/dynamic_group.rb', line 26

def self.taggedGroups
    @taggedGroups
end

Instance Method Details

#extensionObject



121
122
123
# File 'lib/slow_blink/message/dynamic_group.rb', line 121

def extension
    @value.extension
end

#getGroup

Returns contained group.

Returns:

  • (Group)

    contained group



107
108
109
# File 'lib/slow_blink/message/dynamic_group.rb', line 107

def get
    @value.get
end

#set(value) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
# File 'lib/slow_blink/message/dynamic_group.rb', line 94

def set(value)
    if value.kind_of? Group
        if self.class.permittedID.include? value.class.id        
            @value = value
        else                        
            raise TypeError.new "incompatible group"
        end
    else
        raise ArgumentError.new "argument must be kind_of Group"
    end
end

#to_tagObject



125
126
127
# File 'lib/slow_blink/message/dynamic_group.rb', line 125

def to_tag
    "@#{@value.class.name}#{@value.to_tag_value}#{@value.to_tag_extension}"                    
end