Module: DICOM::ElementalParent
Overview
The ElementalParent mix-in module contains methods that are common among the two elemental parent classes: Item & Sequence
Instance Method Summary collapse
-
#add_item(item = nil, options = {}) ⇒ Object
Adds a child item to a Sequence (or Item in some cases where pixel data is encapsulated).
Instance Method Details
#add_item(item = nil, options = {}) ⇒ Object
Note:
Items are specified by index (starting at 0) instead of a tag string!
Adds a child item to a Sequence (or Item in some cases where pixel data is encapsulated).
If no existing Item is given, a new item will be created and added.
option options [Integer] :if specified, forces the item to be inserted at that specific index (Item number) option options [Boolean] :no_follow when true, the method does not update the parent attribute of the child that is added
-
options
– A hash of parameters.
24 25 26 27 28 29 30 31 32 33 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 |
# File 'lib/dicom/elemental_parent.rb', line 24 def add_item(item=nil, ={}) if item if item.is_a?(Item) if index = [:index] # This Item will take a specific index, and all existing Items with index higher or equal to this number will have their index increased by one. # Check if index is valid (must be an existing index): if index >= 0 # If the index value is larger than the max index present, we dont need to modify the existing items. if index < @tags.length @tags = @tags.create_key_gap_at(index) else # Set the index value one higher than the already existing max value: index = @tags.length end #,Add the new Item and set its index: @tags[index] = item item.index = index else raise ArgumentError, "The specified index (#{index}) is out of range (must be a positive integer)." end else # Add the existing Item to this Sequence: index = @tags.length @tags[index] = item # Let the Item know what index key it's got in it's parent's Hash: item.index = index end # Set ourself as this item's new parent: item.set_parent(self) unless [:no_follow] else raise ArgumentError, "Expected Item, got #{item.class}" end else # Create an empty item with self as parent: item = Item.new(:parent => self) end end |