Method: IdPack::IdPacker#decode

Defined in:
lib/id_pack/id_packer.rb

#decode(encoded_caches) ⇒ Object

“_F~C_P.V”

> [5, 6, 21, 23, 25]



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/id_pack/id_packer.rb', line 136

def decode(encoded_caches)
  curr_encoded_string_prefix = nil

  ids = []
  start_id = 0
  encoded_number = ''

  encoded_caches.each_char do |c|
    if [SPACES_PREFIX, BINARY_PREFIX, RANGE_PREFIX].include?(c)
      unless curr_encoded_string_prefix == nil
        ids_to_include, end_id = convert_encoded_number_to_ids(
          curr_encoded_string_prefix, encoded_number, start_id
        )
        ids.concat(ids_to_include)
        start_id = end_id + (c == SPACES_PREFIX ? 0 : 1)
      end
      curr_encoded_string_prefix = c
      encoded_number = ''
    else
      encoded_number = encoded_number + c
    end

  end

  unless curr_encoded_string_prefix == nil
    ids_to_include, end_id = convert_encoded_number_to_ids(
      curr_encoded_string_prefix, encoded_number, start_id
    )
    ids.concat(ids_to_include)
    start_id = end_id + 1
  end

  ids
rescue InvalidEncodedCharException
  # corrupted encoded_caches, assume nothing cached
  []
end