Class: DICOM::Item
- Includes:
- Elemental
- Defined in:
- lib/dicom/item.rb
Overview
The Item class handles information related to items - the elements contained in sequences.
Inheritance
As the Item class inherits from the ImageItem class, which itself inherits from the Parent class, all ImageItem and Parent methods are also available to instances of Item.
Instance Attribute Summary collapse
-
#index ⇒ Object
The index of this Item in the group of items belonging to its parent.
Attributes included from Elemental
#bin, #length, #name, #parent, #tag, #vr
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Checks for equality.
-
#bin=(new_bin) ⇒ Object
Sets the binary string that the Item will contain.
-
#hash ⇒ Fixnum
Computes a hash code for this object.
-
#initialize(options = {}) ⇒ Item
constructor
Creates an Item instance.
-
#parse(bin, syntax) ⇒ Object
Loads data from an encoded DICOM string and creates sequences and elements which are linked to this instance.
-
#to_item ⇒ Item
Returns self.
Methods included from Elemental
#name_as_method, #parents, #set_parent, #stream, #top_parent
Methods inherited from ImageItem
#add_element, #add_sequence, #color?, #compression?, #decode_pixels, #delete_sequences, #encode_pixels, #image, #image=, #image_from_file, #image_strings, #image_to_file, #images, #narray, #num_cols, #num_frames, #num_rows, #pixels, #pixels=
Methods included from ImageProcessor
#decompress, #export_pixels, #import_pixels, #valid_image_objects
Methods inherited from Parent
#[], #add, #add_item, #children, #children?, #count, #count_all, #delete, #delete_children, #delete_group, #delete_private, #delete_retired, #each, #each_element, #each_item, #each_sequence, #each_tag, #elements, #elements?, #encode_children, #exists?, #group, #handle_print, #inspect, #is_parent?, #items, #items?, #length=, #max_lengths, #method_missing, #print, #reset_length, #respond_to?, #sequences, #sequences?, #to_hash, #to_json, #to_yaml, #value
Methods included from Logging
Constructor Details
#initialize(options = {}) ⇒ Item
Creates an Item instance.
Normally, an Item contains data elements and/or sequences. However, in some cases, an Item will instead/also carry binary string data, like the pixel data of an encapsulated image fragment.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/dicom/item.rb', line 37 def initialize(={}) # Set common parent variables: initialize_parent # Set instance variables: @tag = ITEM_TAG @value = nil @name = [:name] || "Item" @vr = [:vr] || ITEM_VR if [:bin] self.bin = [:bin] else @length = [:length] || -1 end if [:parent] @parent = [:parent] @index = [:index] if [:index] @parent.add_item(self, :index => [:index], :no_follow => true) end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class DICOM::Parent
Instance Attribute Details
#index ⇒ Object
The index of this Item in the group of items belonging to its parent. If the Item is without parent, index is nil.
16 17 18 |
# File 'lib/dicom/item.rb', line 16 def index @index end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Checks for equality.
Other and self are considered equivalent if they are of compatible types and their attributes are equivalent.
65 66 67 68 69 |
# File 'lib/dicom/item.rb', line 65 def ==(other) if other.respond_to?(:to_item) other.send(:state) == state end end |
#bin=(new_bin) ⇒ Object
Sets the binary string that the Item will contain.
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/dicom/item.rb', line 79 def bin=(new_bin) raise ArgumentError, "Invalid parameter type. String was expected, got #{new_bin.class}." unless new_bin.is_a?(String) # Add an empty byte at the end if the length of the binary is odd: if new_bin.length.odd? @bin = new_bin + "\x00" else @bin = new_bin end @value = nil @length = @bin.length end |
#hash ⇒ Fixnum
Two objects with the same attributes will have the same hash code.
Computes a hash code for this object.
97 98 99 |
# File 'lib/dicom/item.rb', line 97 def hash state.hash end |
#parse(bin, syntax) ⇒ Object
Loads data from an encoded DICOM string and creates sequences and elements which are linked to this instance.
107 108 109 110 111 |
# File 'lib/dicom/item.rb', line 107 def parse(bin, syntax) raise ArgumentError, "Invalid argument 'bin'. Expected String, got #{bin.class}." unless bin.is_a?(String) raise ArgumentError, "Invalid argument 'syntax'. Expected String, got #{syntax.class}." unless syntax.is_a?(String) read(bin, signature=false, :syntax => syntax) end |