Module: DICOM::Elemental

Included in:
Element, Item, Sequence
Defined in:
lib/dicom/elemental.rb

Overview

The Elemental mix-in module contains methods that are common among the various element type classes:

  • Element

  • Item

  • Sequence

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#binObject (readonly)

The encoded, binary value of the elemental (String).



12
13
14
# File 'lib/dicom/elemental.rb', line 12

def bin
  @bin
end

#lengthObject (readonly)

The elemental’s length (Fixnum).



14
15
16
# File 'lib/dicom/elemental.rb', line 14

def length
  @length
end

#nameObject (readonly)

The elemental’s name (String).



16
17
18
# File 'lib/dicom/elemental.rb', line 16

def name
  @name
end

#parentObject

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

#tagObject (readonly)

The elemental’s tag (String).



20
21
22
# File 'lib/dicom/elemental.rb', line 20

def tag
  @tag
end

#vrObject (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_methodSymbol, NilClass

Gives the method (symbol) corresponding to the name string of this element.

Returns:

  • (Symbol, NilClass)

    the matched element method (or nil, if no match is made)



28
29
30
# File 'lib/dicom/elemental.rb', line 28

def name_as_method
  LIBRARY.as_method(@name)
end

#parentsArray

Retrieves the entire chain of parents connected to this elemental (or an empty array, if the element is parent-less).

Returns:

  • (Array)

    array of parents (immediate parent first, top parent last)



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.

Parameters:



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

#streamObject

Note:

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_parentObject

Note:

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