Class: DICOM::Sequence

Inherits:
Parent
  • Object
show all
Includes:
Elemental
Defined in:
lib/dicom/sequence.rb

Overview

The Sequence class handles information related to Sequence elements.

Instance Attribute Summary

Attributes included from Elemental

#bin, #length, #name, #parent, #tag, #vr

Instance Method Summary collapse

Methods included from Elemental

#name_as_method, #parents, #set_parent, #stream, #top_parent

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

included, #logger

Constructor Details

#initialize(tag, options = {}) ⇒ Sequence

Note:

Private sequences are named as ‘Private’.

Note:

Non-private sequences that are not found in the dictionary are named as ‘Unknown’.

Creates a Sequence instance.

Examples:

Create a new Sequence and connect it to a DObject instance

structure_set_roi = Sequence.new('3006,0020', :parent => dcm)

Create an “Encapsulated Pixel Data” Sequence

encapsulated_pixel_data = Sequence.new('7FE0,0010', :name => 'Encapsulated Pixel Data', :parent => dcm, :vr => 'OW')

Parameters:

  • tag (String)

    a ruby-dicom type element tag string

  • options (Hash) (defaults to: {})

    the options to use for creating the sequence

Options Hash (options):

  • :length (Integer)

    the sequence length, which refers to the length of the encoded string of children of this sequence

  • :name (Integer)

    the name of the sequence may be specified upon creation (if it is not, the name is retrieved from the dictionary)

  • :parent (Integer)

    an Item or DObject instance which the sequence instance shall belong to

  • :vr (Integer)

    the value representation of the Sequence may be specified upon creation (if it is not, a default vr is chosen)

Raises:

  • (ArgumentError)


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/dicom/sequence.rb', line 27

def initialize(tag, options={})
  raise ArgumentError, "The supplied tag (#{tag}) is not valid. The tag must be a string of the form 'GGGG,EEEE'." unless tag.is_a?(String) && tag.tag?
  # Set common parent variables:
  initialize_parent
  # Set instance variables:
  @tag = tag.upcase
  @value = nil
  @bin = nil
  # We may beed to retrieve name and vr from the library:
  if options[:name] and options[:vr]
    @name = options[:name]
    @vr = options[:vr]
  else
    name, vr = LIBRARY.name_and_vr(tag)
    @name = options[:name] || name
    @vr = options[:vr] || 'SQ'
  end
  @length = options[:length] || -1
  if options[:parent]
    @parent = options[:parent]
    @parent.add(self, :no_follow => true)
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class DICOM::Parent

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.

Parameters:

  • other

    an object to be compared with self.

Returns:

  • (Boolean)

    true if self and other are considered equivalent



59
60
61
62
63
# File 'lib/dicom/sequence.rb', line 59

def ==(other)
  if other.respond_to?(:to_sequence)
    other.send(:state) == state
  end
end

#hashFixnum

Note:

Two objects with the same attributes will have the same hash code.

Computes a hash code for this object.

Returns:

  • (Fixnum)

    the object’s hash code



73
74
75
# File 'lib/dicom/sequence.rb', line 73

def hash
  state.hash
end

#parse(bin, syntax) ⇒ Object

Loads data from an encoded DICOM string and creates items and elements which are linked to this instance.

Parameters:

  • bin (String)

    an encoded binary string containing DICOM information

  • syntax (String)

    the transfer syntax to use when decoding the DICOM string

Raises:

  • (ArgumentError)


83
84
85
86
87
# File 'lib/dicom/sequence.rb', line 83

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

#to_sequenceSequence

Returns self.

Returns:



93
94
95
# File 'lib/dicom/sequence.rb', line 93

def to_sequence
  self
end