Module: DICOM::Elemental
Overview
The Elemental mix-in module contains methods that are common among the various element type classes:
-
Element
-
Item
-
Sequence
Instance Attribute Summary collapse
-
#bin ⇒ Object
readonly
The encoded, binary value of the elemental (String).
-
#length ⇒ Object
readonly
The elemental’s length (Fixnum).
-
#name ⇒ Object
readonly
The elemental’s name (String).
-
#parent ⇒ Object
The parent of this elemental (which may be an Item, Sequence or DObject).
-
#tag ⇒ Object
readonly
The elemental’s tag (String).
-
#vr ⇒ Object
readonly
The elemental’s value representation (String).
Instance Method Summary collapse
-
#name_as_method ⇒ Symbol, NilClass
Gives the method (symbol) corresponding to the name string of this element.
-
#parents ⇒ Array
Retrieves the entire chain of parents connected to this elemental (or an empty array, if the element is parent-less).
-
#set_parent(new_parent) ⇒ Object
Sets a specified parent instance as this elemental’s parent, without doing any other updates, like removing the elemental from any previous parent or adding itself to the new parent.
-
#stream ⇒ Object
Returns a Stream instance which can be used for encoding a value to binary.
-
#top_parent ⇒ Object
Returns the top parent of a particular elemental.
Instance Attribute Details
#bin ⇒ Object (readonly)
The encoded, binary value of the elemental (String).
12 13 14 |
# File 'lib/dicom/elemental.rb', line 12 def bin @bin end |
#length ⇒ Object (readonly)
The elemental’s length (Fixnum).
14 15 16 |
# File 'lib/dicom/elemental.rb', line 14 def length @length end |
#name ⇒ Object (readonly)
The elemental’s name (String).
16 17 18 |
# File 'lib/dicom/elemental.rb', line 16 def name @name end |
#parent ⇒ Object
The parent of this elemental (which may be an Item, Sequence or DObject).
18 19 20 |
# File 'lib/dicom/elemental.rb', line 18 def parent @parent end |
#tag ⇒ Object (readonly)
The elemental’s tag (String).
20 21 22 |
# File 'lib/dicom/elemental.rb', line 20 def tag @tag end |
#vr ⇒ Object (readonly)
The elemental’s value representation (String).
22 23 24 |
# File 'lib/dicom/elemental.rb', line 22 def vr @vr end |
Instance Method Details
#name_as_method ⇒ Symbol, NilClass
Gives the method (symbol) corresponding to the name string of this element.
28 29 30 |
# File 'lib/dicom/elemental.rb', line 28 def name_as_method LIBRARY.as_method(@name) end |
#parents ⇒ Array
Retrieves the entire chain of parents connected to this elemental (or an empty array, if the element is parent-less).
37 38 39 40 41 42 43 44 45 |
# File 'lib/dicom/elemental.rb', line 37 def parents all_parents = Array.new # Extract all parents and add to array recursively: if parent all_parents = parent.parents if parent.parent all_parents.insert(0, parent) end return all_parents end |
#set_parent(new_parent) ⇒ Object
Sets a specified parent instance as this elemental’s parent, without doing any other updates, like removing the elemental from any previous parent or adding itself to the new parent.
83 84 85 86 |
# File 'lib/dicom/elemental.rb', line 83 def set_parent(new_parent) # Set the new parent (should we bother to test for parent validity here?): @parent = new_parent end |
#stream ⇒ Object
Retrieves the Stream instance of the top parent DObject instance. If this fails, a new Stream instance is created (with little endian encoding assumed).
Returns a Stream instance which can be used for encoding a value to binary.
93 94 95 96 97 98 99 |
# File 'lib/dicom/elemental.rb', line 93 def stream if top_parent.is_a?(DObject) return top_parent.stream else return Stream.new(nil, file_endian=false) end end |
#top_parent ⇒ Object
Unless the elemental, or one of its parent instances, are independent, the top parent will be a DObject instance.
Returns the top parent of a particular elemental.
106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/dicom/elemental.rb', line 106 def top_parent # The top parent is determined recursively: if parent if parent.is_a?(DObject) return parent else return parent.top_parent end else return self end end |