Method: OpenC3::Structure#delete_item

Defined in:
lib/openc3/packets/structure.rb

#delete_item(name) ⇒ Object

Parameters:

  • name (String)

    Name of the item to delete in the items Hash

Raises:

  • (ArgumentError)


346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
# File 'lib/openc3/packets/structure.rb', line 346

def delete_item(name)
  item = @items[name.upcase]
  raise ArgumentError, "Unknown item: #{name}" unless item

  # Find the item to delete in the sorted_items array
  item_index = nil
  @sorted_items.each_with_index do |sorted_item, index|
    if sorted_item.name == item.name
      item_index = index
      break
    end
  end
  @sorted_items.delete_at(item_index)
  @items.delete(name.upcase)
end