repo
stringlengths 5
58
| path
stringlengths 9
168
| func_name
stringlengths 9
130
| original_string
stringlengths 66
10.5k
| language
stringclasses 1
value | code
stringlengths 66
10.5k
| code_tokens
list | docstring
stringlengths 8
16k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 94
266
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
dicom/ruby-dicom | lib/dicom/parent.rb | DICOM.Parent.value | def value(tag)
check_key(tag, :value)
if exists?(tag)
if self[tag].is_parent?
raise ArgumentError, "Illegal parameter '#{tag}'. Parent elements, like the referenced '#{@tags[tag].class}', have no value. Only Element tags are valid."
else
return self[tag].value
end
else
return nil
end
end | ruby | def value(tag)
check_key(tag, :value)
if exists?(tag)
if self[tag].is_parent?
raise ArgumentError, "Illegal parameter '#{tag}'. Parent elements, like the referenced '#{@tags[tag].class}', have no value. Only Element tags are valid."
else
return self[tag].value
end
else
return nil
end
end | [
"def",
"value",
"(",
"tag",
")",
"check_key",
"(",
"tag",
",",
":value",
")",
"if",
"exists?",
"(",
"tag",
")",
"if",
"self",
"[",
"tag",
"]",
".",
"is_parent?",
"raise",
"ArgumentError",
",",
"\"Illegal parameter '#{tag}'. Parent elements, like the referenced '#{@tags[tag].class}', have no value. Only Element tags are valid.\"",
"else",
"return",
"self",
"[",
"tag",
"]",
".",
"value",
"end",
"else",
"return",
"nil",
"end",
"end"
]
| Gives the value of a specific Element child of this parent.
* Only Element instances have values. Parent elements like Sequence and Item have no value themselves.
* If the specified tag is that of a parent element, an exception is raised.
@param [String] tag a tag string which identifies the child Element
@return [String, Integer, Float, NilClass] an element value (or nil, if no element is matched)
@example Get the patient's name value
name = dcm.value("0010,0010")
@example Get the Frame of Reference UID from the first item in the Referenced Frame of Reference Sequence
uid = dcm["3006,0010"][0].value("0020,0052") | [
"Gives",
"the",
"value",
"of",
"a",
"specific",
"Element",
"child",
"of",
"this",
"parent",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/parent.rb#L640-L651 | train |
dicom/ruby-dicom | lib/dicom/parent.rb | DICOM.Parent.check_key | def check_key(tag_or_index, method)
if tag_or_index.is_a?(String)
logger.warn("Parent##{method} called with an invalid tag argument: #{tag_or_index}") unless tag_or_index.tag?
elsif tag_or_index.is_a?(Integer)
logger.warn("Parent##{method} called with a negative Integer argument: #{tag_or_index}") if tag_or_index < 0
else
logger.warn("Parent##{method} called with an unexpected argument. Expected String or Integer, got: #{tag_or_index.class}")
end
end | ruby | def check_key(tag_or_index, method)
if tag_or_index.is_a?(String)
logger.warn("Parent##{method} called with an invalid tag argument: #{tag_or_index}") unless tag_or_index.tag?
elsif tag_or_index.is_a?(Integer)
logger.warn("Parent##{method} called with a negative Integer argument: #{tag_or_index}") if tag_or_index < 0
else
logger.warn("Parent##{method} called with an unexpected argument. Expected String or Integer, got: #{tag_or_index.class}")
end
end | [
"def",
"check_key",
"(",
"tag_or_index",
",",
"method",
")",
"if",
"tag_or_index",
".",
"is_a?",
"(",
"String",
")",
"logger",
".",
"warn",
"(",
"\"Parent##{method} called with an invalid tag argument: #{tag_or_index}\"",
")",
"unless",
"tag_or_index",
".",
"tag?",
"elsif",
"tag_or_index",
".",
"is_a?",
"(",
"Integer",
")",
"logger",
".",
"warn",
"(",
"\"Parent##{method} called with a negative Integer argument: #{tag_or_index}\"",
")",
"if",
"tag_or_index",
"<",
"0",
"else",
"logger",
".",
"warn",
"(",
"\"Parent##{method} called with an unexpected argument. Expected String or Integer, got: #{tag_or_index.class}\"",
")",
"end",
"end"
]
| Checks the given key argument and logs a warning if an obviously
incorrect key argument is used.
@param [String, Integer] tag_or_index the tag string or item index indentifying a given elemental
@param [Symbol] method a representation of the method calling this method | [
"Checks",
"the",
"given",
"key",
"argument",
"and",
"logs",
"a",
"warning",
"if",
"an",
"obviously",
"incorrect",
"key",
"argument",
"is",
"used",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/parent.rb#L663-L671 | train |
dicom/ruby-dicom | lib/dicom/link.rb | DICOM.Link.await_release | def await_release
segments = receive_single_transmission
info = segments.first
if info[:pdu] != PDU_RELEASE_REQUEST
# For some reason we didn't get our expected release request. Determine why:
if info[:valid]
logger.error("Unexpected message type received (PDU: #{info[:pdu]}). Expected a release request. Closing the connection.")
handle_abort(false)
else
logger.error("Timed out while waiting for a release request. Closing the connection.")
end
stop_session
else
# Properly release the association:
handle_release
end
end | ruby | def await_release
segments = receive_single_transmission
info = segments.first
if info[:pdu] != PDU_RELEASE_REQUEST
# For some reason we didn't get our expected release request. Determine why:
if info[:valid]
logger.error("Unexpected message type received (PDU: #{info[:pdu]}). Expected a release request. Closing the connection.")
handle_abort(false)
else
logger.error("Timed out while waiting for a release request. Closing the connection.")
end
stop_session
else
# Properly release the association:
handle_release
end
end | [
"def",
"await_release",
"segments",
"=",
"receive_single_transmission",
"info",
"=",
"segments",
".",
"first",
"if",
"info",
"[",
":pdu",
"]",
"!=",
"PDU_RELEASE_REQUEST",
"if",
"info",
"[",
":valid",
"]",
"logger",
".",
"error",
"(",
"\"Unexpected message type received (PDU: #{info[:pdu]}). Expected a release request. Closing the connection.\"",
")",
"handle_abort",
"(",
"false",
")",
"else",
"logger",
".",
"error",
"(",
"\"Timed out while waiting for a release request. Closing the connection.\"",
")",
"end",
"stop_session",
"else",
"handle_release",
"end",
"end"
]
| Creates a Link instance, which is used by both DClient and DServer to handle network communication.
=== Parameters
* <tt>options</tt> -- A hash of parameters.
=== Options
* <tt>:ae</tt> -- String. The name of the client (application entity).
* <tt>:file_handler</tt> -- A customized FileHandler class to use instead of the default FileHandler.
* <tt>:host_ae</tt> -- String. The name of the server (application entity).
* <tt>:max_package_size</tt> -- Integer. The maximum allowed size of network packages (in bytes).
* <tt>:timeout</tt> -- Integer. The maximum period to wait for an answer before aborting the communication.
Waits for an SCU to issue a release request, and answers it by launching the handle_release method.
If invalid or no message is received, the connection is closed. | [
"Creates",
"a",
"Link",
"instance",
"which",
"is",
"used",
"by",
"both",
"DClient",
"and",
"DServer",
"to",
"handle",
"network",
"communication",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/link.rb#L57-L73 | train |
dicom/ruby-dicom | lib/dicom/link.rb | DICOM.Link.build_association_request | def build_association_request(presentation_contexts, user_info)
# Big endian encoding:
@outgoing.endian = @net_endian
# Clear the outgoing binary string:
@outgoing.reset
# Note: The order of which these components are built is not arbitrary.
# (The first three are built 'in order of appearance', the header is built last, but is put first in the message)
append_application_context
append_presentation_contexts(presentation_contexts, ITEM_PRESENTATION_CONTEXT_REQUEST, request=true)
append_user_information(user_info)
# Header must be built last, because we need to know the length of the other components.
append_association_header(PDU_ASSOCIATION_REQUEST, @host_ae)
end | ruby | def build_association_request(presentation_contexts, user_info)
# Big endian encoding:
@outgoing.endian = @net_endian
# Clear the outgoing binary string:
@outgoing.reset
# Note: The order of which these components are built is not arbitrary.
# (The first three are built 'in order of appearance', the header is built last, but is put first in the message)
append_application_context
append_presentation_contexts(presentation_contexts, ITEM_PRESENTATION_CONTEXT_REQUEST, request=true)
append_user_information(user_info)
# Header must be built last, because we need to know the length of the other components.
append_association_header(PDU_ASSOCIATION_REQUEST, @host_ae)
end | [
"def",
"build_association_request",
"(",
"presentation_contexts",
",",
"user_info",
")",
"@outgoing",
".",
"endian",
"=",
"@net_endian",
"@outgoing",
".",
"reset",
"append_application_context",
"append_presentation_contexts",
"(",
"presentation_contexts",
",",
"ITEM_PRESENTATION_CONTEXT_REQUEST",
",",
"request",
"=",
"true",
")",
"append_user_information",
"(",
"user_info",
")",
"append_association_header",
"(",
"PDU_ASSOCIATION_REQUEST",
",",
"@host_ae",
")",
"end"
]
| Builds the binary string which is sent as the association request.
=== Parameters
* <tt>presentation_contexts</tt> -- A hash containing abstract_syntaxes, presentation context ids and transfer syntaxes.
* <tt>user_info</tt> -- A user information items array. | [
"Builds",
"the",
"binary",
"string",
"which",
"is",
"sent",
"as",
"the",
"association",
"request",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/link.rb#L167-L179 | train |
dicom/ruby-dicom | lib/dicom/link.rb | DICOM.Link.build_command_fragment | def build_command_fragment(pdu, context, flags, command_elements)
# Little endian encoding:
@outgoing.endian = @data_endian
# Clear the outgoing binary string:
@outgoing.reset
# Build the last part first, the Command items:
command_elements.each do |element|
# Tag (4 bytes)
@outgoing.add_last(@outgoing.encode_tag(element[0]))
# Encode the value first, so we know its length:
value = @outgoing.encode_value(element[2], element[1])
# Length (2 bytes)
@outgoing.encode_last(value.length, "US")
# Reserved (2 bytes)
@outgoing.encode_last("0000", "HEX")
# Value (variable length)
@outgoing.add_last(value)
end
# The rest of the command fragment will be buildt in reverse, all the time
# putting the elements first in the outgoing binary string.
# Group length item:
# Value (4 bytes)
@outgoing.encode_first(@outgoing.string.length, "UL")
# Reserved (2 bytes)
@outgoing.encode_first("0000", "HEX")
# Length (2 bytes)
@outgoing.encode_first(4, "US")
# Tag (4 bytes)
@outgoing.add_first(@outgoing.encode_tag("0000,0000"))
# Big endian encoding from now on:
@outgoing.endian = @net_endian
# Flags (1 byte)
@outgoing.encode_first(flags, "HEX")
# Presentation context ID (1 byte)
@outgoing.encode_first(context, "BY")
# Length (of remaining data) (4 bytes)
@outgoing.encode_first(@outgoing.string.length, "UL")
# PRESENTATION DATA VALUE (the above)
append_header(pdu)
end | ruby | def build_command_fragment(pdu, context, flags, command_elements)
# Little endian encoding:
@outgoing.endian = @data_endian
# Clear the outgoing binary string:
@outgoing.reset
# Build the last part first, the Command items:
command_elements.each do |element|
# Tag (4 bytes)
@outgoing.add_last(@outgoing.encode_tag(element[0]))
# Encode the value first, so we know its length:
value = @outgoing.encode_value(element[2], element[1])
# Length (2 bytes)
@outgoing.encode_last(value.length, "US")
# Reserved (2 bytes)
@outgoing.encode_last("0000", "HEX")
# Value (variable length)
@outgoing.add_last(value)
end
# The rest of the command fragment will be buildt in reverse, all the time
# putting the elements first in the outgoing binary string.
# Group length item:
# Value (4 bytes)
@outgoing.encode_first(@outgoing.string.length, "UL")
# Reserved (2 bytes)
@outgoing.encode_first("0000", "HEX")
# Length (2 bytes)
@outgoing.encode_first(4, "US")
# Tag (4 bytes)
@outgoing.add_first(@outgoing.encode_tag("0000,0000"))
# Big endian encoding from now on:
@outgoing.endian = @net_endian
# Flags (1 byte)
@outgoing.encode_first(flags, "HEX")
# Presentation context ID (1 byte)
@outgoing.encode_first(context, "BY")
# Length (of remaining data) (4 bytes)
@outgoing.encode_first(@outgoing.string.length, "UL")
# PRESENTATION DATA VALUE (the above)
append_header(pdu)
end | [
"def",
"build_command_fragment",
"(",
"pdu",
",",
"context",
",",
"flags",
",",
"command_elements",
")",
"@outgoing",
".",
"endian",
"=",
"@data_endian",
"@outgoing",
".",
"reset",
"command_elements",
".",
"each",
"do",
"|",
"element",
"|",
"@outgoing",
".",
"add_last",
"(",
"@outgoing",
".",
"encode_tag",
"(",
"element",
"[",
"0",
"]",
")",
")",
"value",
"=",
"@outgoing",
".",
"encode_value",
"(",
"element",
"[",
"2",
"]",
",",
"element",
"[",
"1",
"]",
")",
"@outgoing",
".",
"encode_last",
"(",
"value",
".",
"length",
",",
"\"US\"",
")",
"@outgoing",
".",
"encode_last",
"(",
"\"0000\"",
",",
"\"HEX\"",
")",
"@outgoing",
".",
"add_last",
"(",
"value",
")",
"end",
"@outgoing",
".",
"encode_first",
"(",
"@outgoing",
".",
"string",
".",
"length",
",",
"\"UL\"",
")",
"@outgoing",
".",
"encode_first",
"(",
"\"0000\"",
",",
"\"HEX\"",
")",
"@outgoing",
".",
"encode_first",
"(",
"4",
",",
"\"US\"",
")",
"@outgoing",
".",
"add_first",
"(",
"@outgoing",
".",
"encode_tag",
"(",
"\"0000,0000\"",
")",
")",
"@outgoing",
".",
"endian",
"=",
"@net_endian",
"@outgoing",
".",
"encode_first",
"(",
"flags",
",",
"\"HEX\"",
")",
"@outgoing",
".",
"encode_first",
"(",
"context",
",",
"\"BY\"",
")",
"@outgoing",
".",
"encode_first",
"(",
"@outgoing",
".",
"string",
".",
"length",
",",
"\"UL\"",
")",
"append_header",
"(",
"pdu",
")",
"end"
]
| Builds the binary string which is sent as a command fragment.
=== Parameters
* <tt>pdu</tt> -- The command fragment's PDU string.
* <tt>context</tt> -- Presentation context ID byte (references a presentation context from the association).
* <tt>flags</tt> -- The flag string, which identifies if this is the last command fragment or not.
* <tt>command_elements</tt> -- An array of command elements. | [
"Builds",
"the",
"binary",
"string",
"which",
"is",
"sent",
"as",
"a",
"command",
"fragment",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/link.rb#L190-L229 | train |
dicom/ruby-dicom | lib/dicom/link.rb | DICOM.Link.build_data_fragment | def build_data_fragment(data_elements, presentation_context_id)
# Set the transfer syntax to be used for encoding the data fragment:
set_transfer_syntax(@presentation_contexts[presentation_context_id])
# Endianness of data fragment:
@outgoing.endian = @data_endian
# Clear the outgoing binary string:
@outgoing.reset
# Build the last part first, the Data items:
data_elements.each do |element|
# Encode all tags (even tags which are empty):
# Tag (4 bytes)
@outgoing.add_last(@outgoing.encode_tag(element[0]))
# Encode the value in advance of putting it into the message, so we know its length:
vr = LIBRARY.element(element[0]).vr
value = @outgoing.encode_value(element[1], vr)
if @explicit
# Type (VR) (2 bytes)
@outgoing.encode_last(vr, "STR")
# Length (2 bytes)
@outgoing.encode_last(value.length, "US")
else
# Implicit:
# Length (4 bytes)
@outgoing.encode_last(value.length, "UL")
end
# Value (variable length)
@outgoing.add_last(value)
end
# The rest of the data fragment will be built in reverse, all the time
# putting the elements first in the outgoing binary string.
# Big endian encoding from now on:
@outgoing.endian = @net_endian
# Flags (1 byte)
@outgoing.encode_first("02", "HEX") # Data, last fragment (identifier)
# Presentation context ID (1 byte)
@outgoing.encode_first(presentation_context_id, "BY")
# Length (of remaining data) (4 bytes)
@outgoing.encode_first(@outgoing.string.length, "UL")
# PRESENTATION DATA VALUE (the above)
append_header(PDU_DATA)
end | ruby | def build_data_fragment(data_elements, presentation_context_id)
# Set the transfer syntax to be used for encoding the data fragment:
set_transfer_syntax(@presentation_contexts[presentation_context_id])
# Endianness of data fragment:
@outgoing.endian = @data_endian
# Clear the outgoing binary string:
@outgoing.reset
# Build the last part first, the Data items:
data_elements.each do |element|
# Encode all tags (even tags which are empty):
# Tag (4 bytes)
@outgoing.add_last(@outgoing.encode_tag(element[0]))
# Encode the value in advance of putting it into the message, so we know its length:
vr = LIBRARY.element(element[0]).vr
value = @outgoing.encode_value(element[1], vr)
if @explicit
# Type (VR) (2 bytes)
@outgoing.encode_last(vr, "STR")
# Length (2 bytes)
@outgoing.encode_last(value.length, "US")
else
# Implicit:
# Length (4 bytes)
@outgoing.encode_last(value.length, "UL")
end
# Value (variable length)
@outgoing.add_last(value)
end
# The rest of the data fragment will be built in reverse, all the time
# putting the elements first in the outgoing binary string.
# Big endian encoding from now on:
@outgoing.endian = @net_endian
# Flags (1 byte)
@outgoing.encode_first("02", "HEX") # Data, last fragment (identifier)
# Presentation context ID (1 byte)
@outgoing.encode_first(presentation_context_id, "BY")
# Length (of remaining data) (4 bytes)
@outgoing.encode_first(@outgoing.string.length, "UL")
# PRESENTATION DATA VALUE (the above)
append_header(PDU_DATA)
end | [
"def",
"build_data_fragment",
"(",
"data_elements",
",",
"presentation_context_id",
")",
"set_transfer_syntax",
"(",
"@presentation_contexts",
"[",
"presentation_context_id",
"]",
")",
"@outgoing",
".",
"endian",
"=",
"@data_endian",
"@outgoing",
".",
"reset",
"data_elements",
".",
"each",
"do",
"|",
"element",
"|",
"@outgoing",
".",
"add_last",
"(",
"@outgoing",
".",
"encode_tag",
"(",
"element",
"[",
"0",
"]",
")",
")",
"vr",
"=",
"LIBRARY",
".",
"element",
"(",
"element",
"[",
"0",
"]",
")",
".",
"vr",
"value",
"=",
"@outgoing",
".",
"encode_value",
"(",
"element",
"[",
"1",
"]",
",",
"vr",
")",
"if",
"@explicit",
"@outgoing",
".",
"encode_last",
"(",
"vr",
",",
"\"STR\"",
")",
"@outgoing",
".",
"encode_last",
"(",
"value",
".",
"length",
",",
"\"US\"",
")",
"else",
"@outgoing",
".",
"encode_last",
"(",
"value",
".",
"length",
",",
"\"UL\"",
")",
"end",
"@outgoing",
".",
"add_last",
"(",
"value",
")",
"end",
"@outgoing",
".",
"endian",
"=",
"@net_endian",
"@outgoing",
".",
"encode_first",
"(",
"\"02\"",
",",
"\"HEX\"",
")",
"@outgoing",
".",
"encode_first",
"(",
"presentation_context_id",
",",
"\"BY\"",
")",
"@outgoing",
".",
"encode_first",
"(",
"@outgoing",
".",
"string",
".",
"length",
",",
"\"UL\"",
")",
"append_header",
"(",
"PDU_DATA",
")",
"end"
]
| Builds the binary string which is sent as a data fragment.
=== Notes
* The style of encoding will depend on whether we have an implicit or explicit transfer syntax.
=== Parameters
* <tt>data_elements</tt> -- An array of data elements.
* <tt>presentation_context_id</tt> -- Presentation context ID byte (references a presentation context from the association). | [
"Builds",
"the",
"binary",
"string",
"which",
"is",
"sent",
"as",
"a",
"data",
"fragment",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/link.rb#L242-L282 | train |
dicom/ruby-dicom | lib/dicom/link.rb | DICOM.Link.build_storage_fragment | def build_storage_fragment(pdu, context, flags, body)
# Big endian encoding:
@outgoing.endian = @net_endian
# Clear the outgoing binary string:
@outgoing.reset
# Build in reverse, putting elements in front of the binary string:
# Insert the data (body):
@outgoing.add_last(body)
# Flags (1 byte)
@outgoing.encode_first(flags, "HEX")
# Context ID (1 byte)
@outgoing.encode_first(context, "BY")
# PDV Length (of remaining data) (4 bytes)
@outgoing.encode_first(@outgoing.string.length, "UL")
# PRESENTATION DATA VALUE (the above)
append_header(pdu)
end | ruby | def build_storage_fragment(pdu, context, flags, body)
# Big endian encoding:
@outgoing.endian = @net_endian
# Clear the outgoing binary string:
@outgoing.reset
# Build in reverse, putting elements in front of the binary string:
# Insert the data (body):
@outgoing.add_last(body)
# Flags (1 byte)
@outgoing.encode_first(flags, "HEX")
# Context ID (1 byte)
@outgoing.encode_first(context, "BY")
# PDV Length (of remaining data) (4 bytes)
@outgoing.encode_first(@outgoing.string.length, "UL")
# PRESENTATION DATA VALUE (the above)
append_header(pdu)
end | [
"def",
"build_storage_fragment",
"(",
"pdu",
",",
"context",
",",
"flags",
",",
"body",
")",
"@outgoing",
".",
"endian",
"=",
"@net_endian",
"@outgoing",
".",
"reset",
"@outgoing",
".",
"add_last",
"(",
"body",
")",
"@outgoing",
".",
"encode_first",
"(",
"flags",
",",
"\"HEX\"",
")",
"@outgoing",
".",
"encode_first",
"(",
"context",
",",
"\"BY\"",
")",
"@outgoing",
".",
"encode_first",
"(",
"@outgoing",
".",
"string",
".",
"length",
",",
"\"UL\"",
")",
"append_header",
"(",
"pdu",
")",
"end"
]
| Builds the binary string which makes up a C-STORE data fragment.
=== Parameters
* <tt>pdu</tt> -- The data fragment's PDU string.
* <tt>context</tt> -- Presentation context ID byte (references a presentation context from the association).
* <tt>flags</tt> -- The flag string, which identifies if this is the last data fragment or not.
* <tt>body</tt> -- A pre-encoded binary string (typicall a segment of a DICOM file to be transmitted). | [
"Builds",
"the",
"binary",
"string",
"which",
"makes",
"up",
"a",
"C",
"-",
"STORE",
"data",
"fragment",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/link.rb#L317-L333 | train |
dicom/ruby-dicom | lib/dicom/link.rb | DICOM.Link.forward_to_interpret | def forward_to_interpret(message, pdu, file=nil)
case pdu
when PDU_ASSOCIATION_REQUEST
info = interpret_association_request(message)
when PDU_ASSOCIATION_ACCEPT
info = interpret_association_accept(message)
when PDU_ASSOCIATION_REJECT
info = interpret_association_reject(message)
when PDU_DATA
info = interpret_command_and_data(message, file)
when PDU_RELEASE_REQUEST
info = interpret_release_request(message)
when PDU_RELEASE_RESPONSE
info = interpret_release_response(message)
when PDU_ABORT
info = interpret_abort(message)
else
info = {:valid => false}
logger.error("An unknown PDU type was received in the incoming transmission. Can not decode this message. (PDU: #{pdu})")
end
return info
end | ruby | def forward_to_interpret(message, pdu, file=nil)
case pdu
when PDU_ASSOCIATION_REQUEST
info = interpret_association_request(message)
when PDU_ASSOCIATION_ACCEPT
info = interpret_association_accept(message)
when PDU_ASSOCIATION_REJECT
info = interpret_association_reject(message)
when PDU_DATA
info = interpret_command_and_data(message, file)
when PDU_RELEASE_REQUEST
info = interpret_release_request(message)
when PDU_RELEASE_RESPONSE
info = interpret_release_response(message)
when PDU_ABORT
info = interpret_abort(message)
else
info = {:valid => false}
logger.error("An unknown PDU type was received in the incoming transmission. Can not decode this message. (PDU: #{pdu})")
end
return info
end | [
"def",
"forward_to_interpret",
"(",
"message",
",",
"pdu",
",",
"file",
"=",
"nil",
")",
"case",
"pdu",
"when",
"PDU_ASSOCIATION_REQUEST",
"info",
"=",
"interpret_association_request",
"(",
"message",
")",
"when",
"PDU_ASSOCIATION_ACCEPT",
"info",
"=",
"interpret_association_accept",
"(",
"message",
")",
"when",
"PDU_ASSOCIATION_REJECT",
"info",
"=",
"interpret_association_reject",
"(",
"message",
")",
"when",
"PDU_DATA",
"info",
"=",
"interpret_command_and_data",
"(",
"message",
",",
"file",
")",
"when",
"PDU_RELEASE_REQUEST",
"info",
"=",
"interpret_release_request",
"(",
"message",
")",
"when",
"PDU_RELEASE_RESPONSE",
"info",
"=",
"interpret_release_response",
"(",
"message",
")",
"when",
"PDU_ABORT",
"info",
"=",
"interpret_abort",
"(",
"message",
")",
"else",
"info",
"=",
"{",
":valid",
"=>",
"false",
"}",
"logger",
".",
"error",
"(",
"\"An unknown PDU type was received in the incoming transmission. Can not decode this message. (PDU: #{pdu})\"",
")",
"end",
"return",
"info",
"end"
]
| Delegates an incoming message to its appropriate interpreter method, based on its pdu type.
Returns the interpreted information hash.
=== Parameters
* <tt>message</tt> -- The binary message string.
* <tt>pdu</tt> -- The PDU string of the message.
* <tt>file</tt> -- A boolean used to inform whether an incoming data fragment is part of a DICOM file reception or not. | [
"Delegates",
"an",
"incoming",
"message",
"to",
"its",
"appropriate",
"interpreter",
"method",
"based",
"on",
"its",
"pdu",
"type",
".",
"Returns",
"the",
"interpreted",
"information",
"hash",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/link.rb#L344-L365 | train |
dicom/ruby-dicom | lib/dicom/link.rb | DICOM.Link.handle_incoming_data | def handle_incoming_data(path)
# Wait for incoming data:
segments = receive_multiple_transmissions(file=true)
# Reset command results arrays:
@command_results = Array.new
@data_results = Array.new
file_transfer_syntaxes = Array.new
files = Array.new
single_file_data = Array.new
# Proceed to extract data from the captured segments:
segments.each do |info|
if info[:valid]
# Determine if it is command or data:
if info[:presentation_context_flag] == DATA_MORE_FRAGMENTS
@data_results << info[:results]
single_file_data << info[:bin]
elsif info[:presentation_context_flag] == DATA_LAST_FRAGMENT
@data_results << info[:results]
single_file_data << info[:bin]
# Join the recorded data binary strings together to make a DICOM file binary string and put it in our files Array:
files << single_file_data.join
single_file_data = Array.new
elsif info[:presentation_context_flag] == COMMAND_LAST_FRAGMENT
@command_results << info[:results]
@presentation_context_id = info[:presentation_context_id] # Does this actually do anything useful?
file_transfer_syntaxes << @presentation_contexts[info[:presentation_context_id]]
end
end
end
# Process the received files using the customizable FileHandler class:
success, messages = @file_handler.receive_files(path, files, file_transfer_syntaxes)
return success, messages
end | ruby | def handle_incoming_data(path)
# Wait for incoming data:
segments = receive_multiple_transmissions(file=true)
# Reset command results arrays:
@command_results = Array.new
@data_results = Array.new
file_transfer_syntaxes = Array.new
files = Array.new
single_file_data = Array.new
# Proceed to extract data from the captured segments:
segments.each do |info|
if info[:valid]
# Determine if it is command or data:
if info[:presentation_context_flag] == DATA_MORE_FRAGMENTS
@data_results << info[:results]
single_file_data << info[:bin]
elsif info[:presentation_context_flag] == DATA_LAST_FRAGMENT
@data_results << info[:results]
single_file_data << info[:bin]
# Join the recorded data binary strings together to make a DICOM file binary string and put it in our files Array:
files << single_file_data.join
single_file_data = Array.new
elsif info[:presentation_context_flag] == COMMAND_LAST_FRAGMENT
@command_results << info[:results]
@presentation_context_id = info[:presentation_context_id] # Does this actually do anything useful?
file_transfer_syntaxes << @presentation_contexts[info[:presentation_context_id]]
end
end
end
# Process the received files using the customizable FileHandler class:
success, messages = @file_handler.receive_files(path, files, file_transfer_syntaxes)
return success, messages
end | [
"def",
"handle_incoming_data",
"(",
"path",
")",
"segments",
"=",
"receive_multiple_transmissions",
"(",
"file",
"=",
"true",
")",
"@command_results",
"=",
"Array",
".",
"new",
"@data_results",
"=",
"Array",
".",
"new",
"file_transfer_syntaxes",
"=",
"Array",
".",
"new",
"files",
"=",
"Array",
".",
"new",
"single_file_data",
"=",
"Array",
".",
"new",
"segments",
".",
"each",
"do",
"|",
"info",
"|",
"if",
"info",
"[",
":valid",
"]",
"if",
"info",
"[",
":presentation_context_flag",
"]",
"==",
"DATA_MORE_FRAGMENTS",
"@data_results",
"<<",
"info",
"[",
":results",
"]",
"single_file_data",
"<<",
"info",
"[",
":bin",
"]",
"elsif",
"info",
"[",
":presentation_context_flag",
"]",
"==",
"DATA_LAST_FRAGMENT",
"@data_results",
"<<",
"info",
"[",
":results",
"]",
"single_file_data",
"<<",
"info",
"[",
":bin",
"]",
"files",
"<<",
"single_file_data",
".",
"join",
"single_file_data",
"=",
"Array",
".",
"new",
"elsif",
"info",
"[",
":presentation_context_flag",
"]",
"==",
"COMMAND_LAST_FRAGMENT",
"@command_results",
"<<",
"info",
"[",
":results",
"]",
"@presentation_context_id",
"=",
"info",
"[",
":presentation_context_id",
"]",
"file_transfer_syntaxes",
"<<",
"@presentation_contexts",
"[",
"info",
"[",
":presentation_context_id",
"]",
"]",
"end",
"end",
"end",
"success",
",",
"messages",
"=",
"@file_handler",
".",
"receive_files",
"(",
"path",
",",
"files",
",",
"file_transfer_syntaxes",
")",
"return",
"success",
",",
"messages",
"end"
]
| Processes incoming command & data fragments for the DServer.
Returns a success boolean and an array of status messages.
=== Notes
The incoming traffic will in most cases be: A C-STORE-RQ (command fragment) followed by a bunch of data fragments.
However, it may also be a C-ECHO-RQ command fragment, which is used to test connections.
=== Parameters
* <tt>path</tt> -- The path used to save incoming DICOM files.
--
FIXME: The code which handles incoming data isnt quite satisfactory. It would probably be wise to rewrite it at some stage to clean up
the code somewhat. Probably a better handling of command requests (and their corresponding data fragments) would be a good idea. | [
"Processes",
"incoming",
"command",
"&",
"data",
"fragments",
"for",
"the",
"DServer",
".",
"Returns",
"a",
"success",
"boolean",
"and",
"an",
"array",
"of",
"status",
"messages",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/link.rb#L410-L442 | train |
dicom/ruby-dicom | lib/dicom/link.rb | DICOM.Link.handle_response | def handle_response
# Need to construct the command elements array:
command_elements = Array.new
# SOP Class UID:
command_elements << ["0000,0002", "UI", @command_request["0000,0002"]]
# Command Field:
command_elements << ["0000,0100", "US", command_field_response(@command_request["0000,0100"])]
# Message ID Being Responded To:
command_elements << ["0000,0120", "US", @command_request["0000,0110"]]
# Data Set Type:
command_elements << ["0000,0800", "US", NO_DATA_SET_PRESENT]
# Status:
command_elements << ["0000,0900", "US", SUCCESS]
# Affected SOP Instance UID:
command_elements << ["0000,1000", "UI", @command_request["0000,1000"]] if @command_request["0000,1000"]
build_command_fragment(PDU_DATA, @presentation_context_id, COMMAND_LAST_FRAGMENT, command_elements)
transmit
end | ruby | def handle_response
# Need to construct the command elements array:
command_elements = Array.new
# SOP Class UID:
command_elements << ["0000,0002", "UI", @command_request["0000,0002"]]
# Command Field:
command_elements << ["0000,0100", "US", command_field_response(@command_request["0000,0100"])]
# Message ID Being Responded To:
command_elements << ["0000,0120", "US", @command_request["0000,0110"]]
# Data Set Type:
command_elements << ["0000,0800", "US", NO_DATA_SET_PRESENT]
# Status:
command_elements << ["0000,0900", "US", SUCCESS]
# Affected SOP Instance UID:
command_elements << ["0000,1000", "UI", @command_request["0000,1000"]] if @command_request["0000,1000"]
build_command_fragment(PDU_DATA, @presentation_context_id, COMMAND_LAST_FRAGMENT, command_elements)
transmit
end | [
"def",
"handle_response",
"command_elements",
"=",
"Array",
".",
"new",
"command_elements",
"<<",
"[",
"\"0000,0002\"",
",",
"\"UI\"",
",",
"@command_request",
"[",
"\"0000,0002\"",
"]",
"]",
"command_elements",
"<<",
"[",
"\"0000,0100\"",
",",
"\"US\"",
",",
"command_field_response",
"(",
"@command_request",
"[",
"\"0000,0100\"",
"]",
")",
"]",
"command_elements",
"<<",
"[",
"\"0000,0120\"",
",",
"\"US\"",
",",
"@command_request",
"[",
"\"0000,0110\"",
"]",
"]",
"command_elements",
"<<",
"[",
"\"0000,0800\"",
",",
"\"US\"",
",",
"NO_DATA_SET_PRESENT",
"]",
"command_elements",
"<<",
"[",
"\"0000,0900\"",
",",
"\"US\"",
",",
"SUCCESS",
"]",
"command_elements",
"<<",
"[",
"\"0000,1000\"",
",",
"\"UI\"",
",",
"@command_request",
"[",
"\"0000,1000\"",
"]",
"]",
"if",
"@command_request",
"[",
"\"0000,1000\"",
"]",
"build_command_fragment",
"(",
"PDU_DATA",
",",
"@presentation_context_id",
",",
"COMMAND_LAST_FRAGMENT",
",",
"command_elements",
")",
"transmit",
"end"
]
| Handles the command fragment response.
=== Notes
This is usually a C-STORE-RSP which follows the (successful) reception of a DICOM file, but may also
be a C-ECHO-RSP in response to an echo request. | [
"Handles",
"the",
"command",
"fragment",
"response",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/link.rb#L472-L489 | train |
dicom/ruby-dicom | lib/dicom/link.rb | DICOM.Link.interpret | def interpret(message, file=nil)
if @first_part
message = @first_part + message
@first_part = nil
end
segments = Array.new
# If the message is at least 8 bytes we can start decoding it:
if message.length > 8
# Create a new Stream instance to handle this response.
msg = Stream.new(message, @net_endian)
# PDU type ( 1 byte)
pdu = msg.decode(1, "HEX")
# Reserved (1 byte)
msg.skip(1)
# Length of remaining data (4 bytes)
specified_length = msg.decode(4, "UL")
# Analyze the remaining length of the message versurs the specified_length value:
if msg.rest_length > specified_length
# If the remaining length of the string itself is bigger than this specified_length value,
# then it seems that we have another message appended in our incoming transmission.
fragment = msg.extract(specified_length)
info = forward_to_interpret(fragment, pdu, file)
info[:pdu] = pdu
segments << info
# It is possible that a fragment contains both a command and a data fragment. If so, we need to make sure we collect all the information:
if info[:rest_string]
additional_info = forward_to_interpret(info[:rest_string], pdu, file)
segments << additional_info
end
# The information gathered from the interpretation is appended to a segments array,
# and in the case of a recursive call some special logic is needed to build this array in the expected fashion.
remaining_segments = interpret(msg.rest_string, file)
remaining_segments.each do |remaining|
segments << remaining
end
elsif msg.rest_length == specified_length
# Proceed to analyze the rest of the message:
fragment = msg.extract(specified_length)
info = forward_to_interpret(fragment, pdu, file)
info[:pdu] = pdu
segments << info
# It is possible that a fragment contains both a command and a data fragment. If so, we need to make sure we collect all the information:
if info[:rest_string]
additional_info = forward_to_interpret(info[:rest_string], pdu, file)
segments << additional_info
end
else
# Length of the message is less than what is specified in the message. Need to listen for more. This is hopefully handled properly now.
#logger.error("Error. The length of the received message (#{msg.rest_length}) is smaller than what it claims (#{specified_length}). Aborting.")
@first_part = msg.string
end
else
# Assume that this is only the start of the message, and add it to the next incoming string:
@first_part = message
end
return segments
end | ruby | def interpret(message, file=nil)
if @first_part
message = @first_part + message
@first_part = nil
end
segments = Array.new
# If the message is at least 8 bytes we can start decoding it:
if message.length > 8
# Create a new Stream instance to handle this response.
msg = Stream.new(message, @net_endian)
# PDU type ( 1 byte)
pdu = msg.decode(1, "HEX")
# Reserved (1 byte)
msg.skip(1)
# Length of remaining data (4 bytes)
specified_length = msg.decode(4, "UL")
# Analyze the remaining length of the message versurs the specified_length value:
if msg.rest_length > specified_length
# If the remaining length of the string itself is bigger than this specified_length value,
# then it seems that we have another message appended in our incoming transmission.
fragment = msg.extract(specified_length)
info = forward_to_interpret(fragment, pdu, file)
info[:pdu] = pdu
segments << info
# It is possible that a fragment contains both a command and a data fragment. If so, we need to make sure we collect all the information:
if info[:rest_string]
additional_info = forward_to_interpret(info[:rest_string], pdu, file)
segments << additional_info
end
# The information gathered from the interpretation is appended to a segments array,
# and in the case of a recursive call some special logic is needed to build this array in the expected fashion.
remaining_segments = interpret(msg.rest_string, file)
remaining_segments.each do |remaining|
segments << remaining
end
elsif msg.rest_length == specified_length
# Proceed to analyze the rest of the message:
fragment = msg.extract(specified_length)
info = forward_to_interpret(fragment, pdu, file)
info[:pdu] = pdu
segments << info
# It is possible that a fragment contains both a command and a data fragment. If so, we need to make sure we collect all the information:
if info[:rest_string]
additional_info = forward_to_interpret(info[:rest_string], pdu, file)
segments << additional_info
end
else
# Length of the message is less than what is specified in the message. Need to listen for more. This is hopefully handled properly now.
#logger.error("Error. The length of the received message (#{msg.rest_length}) is smaller than what it claims (#{specified_length}). Aborting.")
@first_part = msg.string
end
else
# Assume that this is only the start of the message, and add it to the next incoming string:
@first_part = message
end
return segments
end | [
"def",
"interpret",
"(",
"message",
",",
"file",
"=",
"nil",
")",
"if",
"@first_part",
"message",
"=",
"@first_part",
"+",
"message",
"@first_part",
"=",
"nil",
"end",
"segments",
"=",
"Array",
".",
"new",
"if",
"message",
".",
"length",
">",
"8",
"msg",
"=",
"Stream",
".",
"new",
"(",
"message",
",",
"@net_endian",
")",
"pdu",
"=",
"msg",
".",
"decode",
"(",
"1",
",",
"\"HEX\"",
")",
"msg",
".",
"skip",
"(",
"1",
")",
"specified_length",
"=",
"msg",
".",
"decode",
"(",
"4",
",",
"\"UL\"",
")",
"if",
"msg",
".",
"rest_length",
">",
"specified_length",
"fragment",
"=",
"msg",
".",
"extract",
"(",
"specified_length",
")",
"info",
"=",
"forward_to_interpret",
"(",
"fragment",
",",
"pdu",
",",
"file",
")",
"info",
"[",
":pdu",
"]",
"=",
"pdu",
"segments",
"<<",
"info",
"if",
"info",
"[",
":rest_string",
"]",
"additional_info",
"=",
"forward_to_interpret",
"(",
"info",
"[",
":rest_string",
"]",
",",
"pdu",
",",
"file",
")",
"segments",
"<<",
"additional_info",
"end",
"remaining_segments",
"=",
"interpret",
"(",
"msg",
".",
"rest_string",
",",
"file",
")",
"remaining_segments",
".",
"each",
"do",
"|",
"remaining",
"|",
"segments",
"<<",
"remaining",
"end",
"elsif",
"msg",
".",
"rest_length",
"==",
"specified_length",
"fragment",
"=",
"msg",
".",
"extract",
"(",
"specified_length",
")",
"info",
"=",
"forward_to_interpret",
"(",
"fragment",
",",
"pdu",
",",
"file",
")",
"info",
"[",
":pdu",
"]",
"=",
"pdu",
"segments",
"<<",
"info",
"if",
"info",
"[",
":rest_string",
"]",
"additional_info",
"=",
"forward_to_interpret",
"(",
"info",
"[",
":rest_string",
"]",
",",
"pdu",
",",
"file",
")",
"segments",
"<<",
"additional_info",
"end",
"else",
"@first_part",
"=",
"msg",
".",
"string",
"end",
"else",
"@first_part",
"=",
"message",
"end",
"return",
"segments",
"end"
]
| Decodes the header of an incoming message, analyzes its real length versus expected length, and handles any
deviations to make sure that message strings are split up appropriately before they are being forwarded to interpretation.
Returns an array of information hashes.
=== Parameters
* <tt>message</tt> -- The binary message string.
* <tt>file</tt> -- A boolean used to inform whether an incoming data fragment is part of a DICOM file reception or not.
--
FIXME: This method is rather complex and doesnt feature the best readability. A rewrite that is able to simplify it would be lovely. | [
"Decodes",
"the",
"header",
"of",
"an",
"incoming",
"message",
"analyzes",
"its",
"real",
"length",
"versus",
"expected",
"length",
"and",
"handles",
"any",
"deviations",
"to",
"make",
"sure",
"that",
"message",
"strings",
"are",
"split",
"up",
"appropriately",
"before",
"they",
"are",
"being",
"forwarded",
"to",
"interpretation",
".",
"Returns",
"an",
"array",
"of",
"information",
"hashes",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/link.rb#L503-L559 | train |
dicom/ruby-dicom | lib/dicom/link.rb | DICOM.Link.interpret_abort | def interpret_abort(message)
info = Hash.new
msg = Stream.new(message, @net_endian)
# Reserved (2 bytes)
reserved_bytes = msg.skip(2)
# Source (1 byte)
info[:source] = msg.decode(1, "HEX")
# Reason/Diag. (1 byte)
info[:reason] = msg.decode(1, "HEX")
# Analyse the results:
process_source(info[:source])
process_reason(info[:reason])
stop_receiving
@abort = true
info[:valid] = true
return info
end | ruby | def interpret_abort(message)
info = Hash.new
msg = Stream.new(message, @net_endian)
# Reserved (2 bytes)
reserved_bytes = msg.skip(2)
# Source (1 byte)
info[:source] = msg.decode(1, "HEX")
# Reason/Diag. (1 byte)
info[:reason] = msg.decode(1, "HEX")
# Analyse the results:
process_source(info[:source])
process_reason(info[:reason])
stop_receiving
@abort = true
info[:valid] = true
return info
end | [
"def",
"interpret_abort",
"(",
"message",
")",
"info",
"=",
"Hash",
".",
"new",
"msg",
"=",
"Stream",
".",
"new",
"(",
"message",
",",
"@net_endian",
")",
"reserved_bytes",
"=",
"msg",
".",
"skip",
"(",
"2",
")",
"info",
"[",
":source",
"]",
"=",
"msg",
".",
"decode",
"(",
"1",
",",
"\"HEX\"",
")",
"info",
"[",
":reason",
"]",
"=",
"msg",
".",
"decode",
"(",
"1",
",",
"\"HEX\"",
")",
"process_source",
"(",
"info",
"[",
":source",
"]",
")",
"process_reason",
"(",
"info",
"[",
":reason",
"]",
")",
"stop_receiving",
"@abort",
"=",
"true",
"info",
"[",
":valid",
"]",
"=",
"true",
"return",
"info",
"end"
]
| Decodes the message received when the remote node wishes to abort the session.
Returns the processed information hash.
=== Parameters
* <tt>message</tt> -- The binary message string. | [
"Decodes",
"the",
"message",
"received",
"when",
"the",
"remote",
"node",
"wishes",
"to",
"abort",
"the",
"session",
".",
"Returns",
"the",
"processed",
"information",
"hash",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/link.rb#L568-L584 | train |
dicom/ruby-dicom | lib/dicom/link.rb | DICOM.Link.interpret_association_reject | def interpret_association_reject(message)
info = Hash.new
msg = Stream.new(message, @net_endian)
# Reserved (1 byte)
msg.skip(1)
# Result (1 byte)
info[:result] = msg.decode(1, "BY") # 1 for permanent and 2 for transient rejection
# Source (1 byte)
info[:source] = msg.decode(1, "BY")
# Reason (1 byte)
info[:reason] = msg.decode(1, "BY")
logger.warn("ASSOCIATE Request was rejected by the host. Error codes: Result: #{info[:result]}, Source: #{info[:source]}, Reason: #{info[:reason]} (See DICOM PS3.8: Table 9-21 for details.)")
stop_receiving
info[:valid] = true
return info
end | ruby | def interpret_association_reject(message)
info = Hash.new
msg = Stream.new(message, @net_endian)
# Reserved (1 byte)
msg.skip(1)
# Result (1 byte)
info[:result] = msg.decode(1, "BY") # 1 for permanent and 2 for transient rejection
# Source (1 byte)
info[:source] = msg.decode(1, "BY")
# Reason (1 byte)
info[:reason] = msg.decode(1, "BY")
logger.warn("ASSOCIATE Request was rejected by the host. Error codes: Result: #{info[:result]}, Source: #{info[:source]}, Reason: #{info[:reason]} (See DICOM PS3.8: Table 9-21 for details.)")
stop_receiving
info[:valid] = true
return info
end | [
"def",
"interpret_association_reject",
"(",
"message",
")",
"info",
"=",
"Hash",
".",
"new",
"msg",
"=",
"Stream",
".",
"new",
"(",
"message",
",",
"@net_endian",
")",
"msg",
".",
"skip",
"(",
"1",
")",
"info",
"[",
":result",
"]",
"=",
"msg",
".",
"decode",
"(",
"1",
",",
"\"BY\"",
")",
"info",
"[",
":source",
"]",
"=",
"msg",
".",
"decode",
"(",
"1",
",",
"\"BY\"",
")",
"info",
"[",
":reason",
"]",
"=",
"msg",
".",
"decode",
"(",
"1",
",",
"\"BY\"",
")",
"logger",
".",
"warn",
"(",
"\"ASSOCIATE Request was rejected by the host. Error codes: Result: #{info[:result]}, Source: #{info[:source]}, Reason: #{info[:reason]} (See DICOM PS3.8: Table 9-21 for details.)\"",
")",
"stop_receiving",
"info",
"[",
":valid",
"]",
"=",
"true",
"return",
"info",
"end"
]
| Decodes the association reject message and extracts the error reasons given.
Returns the processed information hash.
=== Parameters
* <tt>message</tt> -- The binary message string. | [
"Decodes",
"the",
"association",
"reject",
"message",
"and",
"extracts",
"the",
"error",
"reasons",
"given",
".",
"Returns",
"the",
"processed",
"information",
"hash",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/link.rb#L716-L731 | train |
dicom/ruby-dicom | lib/dicom/link.rb | DICOM.Link.interpret_release_request | def interpret_release_request(message)
info = Hash.new
msg = Stream.new(message, @net_endian)
# Reserved (4 bytes)
reserved_bytes = msg.decode(4, "HEX")
handle_release
info[:valid] = true
return info
end | ruby | def interpret_release_request(message)
info = Hash.new
msg = Stream.new(message, @net_endian)
# Reserved (4 bytes)
reserved_bytes = msg.decode(4, "HEX")
handle_release
info[:valid] = true
return info
end | [
"def",
"interpret_release_request",
"(",
"message",
")",
"info",
"=",
"Hash",
".",
"new",
"msg",
"=",
"Stream",
".",
"new",
"(",
"message",
",",
"@net_endian",
")",
"reserved_bytes",
"=",
"msg",
".",
"decode",
"(",
"4",
",",
"\"HEX\"",
")",
"handle_release",
"info",
"[",
":valid",
"]",
"=",
"true",
"return",
"info",
"end"
]
| Decodes the message received in the release request and calls the handle_release method.
Returns the processed information hash.
=== Parameters
* <tt>message</tt> -- The binary message string. | [
"Decodes",
"the",
"message",
"received",
"in",
"the",
"release",
"request",
"and",
"calls",
"the",
"handle_release",
"method",
".",
"Returns",
"the",
"processed",
"information",
"hash",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/link.rb#L999-L1007 | train |
dicom/ruby-dicom | lib/dicom/link.rb | DICOM.Link.interpret_release_response | def interpret_release_response(message)
info = Hash.new
msg = Stream.new(message, @net_endian)
# Reserved (4 bytes)
reserved_bytes = msg.decode(4, "HEX")
stop_receiving
info[:valid] = true
return info
end | ruby | def interpret_release_response(message)
info = Hash.new
msg = Stream.new(message, @net_endian)
# Reserved (4 bytes)
reserved_bytes = msg.decode(4, "HEX")
stop_receiving
info[:valid] = true
return info
end | [
"def",
"interpret_release_response",
"(",
"message",
")",
"info",
"=",
"Hash",
".",
"new",
"msg",
"=",
"Stream",
".",
"new",
"(",
"message",
",",
"@net_endian",
")",
"reserved_bytes",
"=",
"msg",
".",
"decode",
"(",
"4",
",",
"\"HEX\"",
")",
"stop_receiving",
"info",
"[",
":valid",
"]",
"=",
"true",
"return",
"info",
"end"
]
| Decodes the message received in the release response and closes the connection.
Returns the processed information hash.
=== Parameters
* <tt>message</tt> -- The binary message string. | [
"Decodes",
"the",
"message",
"received",
"in",
"the",
"release",
"response",
"and",
"closes",
"the",
"connection",
".",
"Returns",
"the",
"processed",
"information",
"hash",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/link.rb#L1016-L1024 | train |
dicom/ruby-dicom | lib/dicom/link.rb | DICOM.Link.receive_multiple_transmissions | def receive_multiple_transmissions(file=nil)
# FIXME: The code which waits for incoming network packets seems to be very CPU intensive.
# Perhaps there is a more elegant way to wait for incoming messages?
#
@listen = true
segments = Array.new
while @listen
# Receive data and append the current data to our segments array, which will be returned.
data = receive_transmission(@min_length)
current_segments = interpret(data, file)
if current_segments
current_segments.each do |cs|
segments << cs
end
end
end
segments << {:valid => false} unless segments
return segments
end | ruby | def receive_multiple_transmissions(file=nil)
# FIXME: The code which waits for incoming network packets seems to be very CPU intensive.
# Perhaps there is a more elegant way to wait for incoming messages?
#
@listen = true
segments = Array.new
while @listen
# Receive data and append the current data to our segments array, which will be returned.
data = receive_transmission(@min_length)
current_segments = interpret(data, file)
if current_segments
current_segments.each do |cs|
segments << cs
end
end
end
segments << {:valid => false} unless segments
return segments
end | [
"def",
"receive_multiple_transmissions",
"(",
"file",
"=",
"nil",
")",
"@listen",
"=",
"true",
"segments",
"=",
"Array",
".",
"new",
"while",
"@listen",
"data",
"=",
"receive_transmission",
"(",
"@min_length",
")",
"current_segments",
"=",
"interpret",
"(",
"data",
",",
"file",
")",
"if",
"current_segments",
"current_segments",
".",
"each",
"do",
"|",
"cs",
"|",
"segments",
"<<",
"cs",
"end",
"end",
"end",
"segments",
"<<",
"{",
":valid",
"=>",
"false",
"}",
"unless",
"segments",
"return",
"segments",
"end"
]
| Handles the reception of multiple incoming transmissions.
Returns an array of interpreted message information hashes.
=== Parameters
* <tt>file</tt> -- A boolean used to inform whether an incoming data fragment is part of a DICOM file reception or not. | [
"Handles",
"the",
"reception",
"of",
"multiple",
"incoming",
"transmissions",
".",
"Returns",
"an",
"array",
"of",
"interpreted",
"message",
"information",
"hashes",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/link.rb#L1033-L1051 | train |
dicom/ruby-dicom | lib/dicom/link.rb | DICOM.Link.receive_single_transmission | def receive_single_transmission
min_length = 8
data = receive_transmission(min_length)
segments = interpret(data)
segments << {:valid => false} unless segments.length > 0
return segments
end | ruby | def receive_single_transmission
min_length = 8
data = receive_transmission(min_length)
segments = interpret(data)
segments << {:valid => false} unless segments.length > 0
return segments
end | [
"def",
"receive_single_transmission",
"min_length",
"=",
"8",
"data",
"=",
"receive_transmission",
"(",
"min_length",
")",
"segments",
"=",
"interpret",
"(",
"data",
")",
"segments",
"<<",
"{",
":valid",
"=>",
"false",
"}",
"unless",
"segments",
".",
"length",
">",
"0",
"return",
"segments",
"end"
]
| Handles the reception of a single, expected incoming transmission and returns the interpreted, received data. | [
"Handles",
"the",
"reception",
"of",
"a",
"single",
"expected",
"incoming",
"transmission",
"and",
"returns",
"the",
"interpreted",
"received",
"data",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/link.rb#L1055-L1061 | train |
dicom/ruby-dicom | lib/dicom/link.rb | DICOM.Link.process_reason | def process_reason(reason)
case reason
when "00"
logger.error("Reason specified for abort: Reason not specified")
when "01"
logger.error("Reason specified for abort: Unrecognized PDU")
when "02"
logger.error("Reason specified for abort: Unexpected PDU")
when "04"
logger.error("Reason specified for abort: Unrecognized PDU parameter")
when "05"
logger.error("Reason specified for abort: Unexpected PDU parameter")
when "06"
logger.error("Reason specified for abort: Invalid PDU parameter value")
else
logger.error("Reason specified for abort: Unknown reason (Error code: #{reason})")
end
end | ruby | def process_reason(reason)
case reason
when "00"
logger.error("Reason specified for abort: Reason not specified")
when "01"
logger.error("Reason specified for abort: Unrecognized PDU")
when "02"
logger.error("Reason specified for abort: Unexpected PDU")
when "04"
logger.error("Reason specified for abort: Unrecognized PDU parameter")
when "05"
logger.error("Reason specified for abort: Unexpected PDU parameter")
when "06"
logger.error("Reason specified for abort: Invalid PDU parameter value")
else
logger.error("Reason specified for abort: Unknown reason (Error code: #{reason})")
end
end | [
"def",
"process_reason",
"(",
"reason",
")",
"case",
"reason",
"when",
"\"00\"",
"logger",
".",
"error",
"(",
"\"Reason specified for abort: Reason not specified\"",
")",
"when",
"\"01\"",
"logger",
".",
"error",
"(",
"\"Reason specified for abort: Unrecognized PDU\"",
")",
"when",
"\"02\"",
"logger",
".",
"error",
"(",
"\"Reason specified for abort: Unexpected PDU\"",
")",
"when",
"\"04\"",
"logger",
".",
"error",
"(",
"\"Reason specified for abort: Unrecognized PDU parameter\"",
")",
"when",
"\"05\"",
"logger",
".",
"error",
"(",
"\"Reason specified for abort: Unexpected PDU parameter\"",
")",
"when",
"\"06\"",
"logger",
".",
"error",
"(",
"\"Reason specified for abort: Invalid PDU parameter value\"",
")",
"else",
"logger",
".",
"error",
"(",
"\"Reason specified for abort: Unknown reason (Error code: #{reason})\"",
")",
"end",
"end"
]
| Processes the value of the reason byte received in the association abort, and prints an explanation of the error.
=== Parameters
* <tt>reason</tt> -- String. Reason code for an error that has occured. | [
"Processes",
"the",
"value",
"of",
"the",
"reason",
"byte",
"received",
"in",
"the",
"association",
"abort",
"and",
"prints",
"an",
"explanation",
"of",
"the",
"error",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/link.rb#L1278-L1295 | train |
dicom/ruby-dicom | lib/dicom/link.rb | DICOM.Link.process_result | def process_result(result)
unless result == 0
# Analyse the result and report what is wrong:
case result
when 1
logger.warn("DICOM Request was rejected by the host, reason: 'User-rejection'")
when 2
logger.warn("DICOM Request was rejected by the host, reason: 'No reason (provider rejection)'")
when 3
logger.warn("DICOM Request was rejected by the host, reason: 'Abstract syntax not supported'")
when 4
logger.warn("DICOM Request was rejected by the host, reason: 'Transfer syntaxes not supported'")
else
logger.warn("DICOM Request was rejected by the host, reason: 'UNKNOWN (#{result})' (Illegal reason provided)")
end
end
end | ruby | def process_result(result)
unless result == 0
# Analyse the result and report what is wrong:
case result
when 1
logger.warn("DICOM Request was rejected by the host, reason: 'User-rejection'")
when 2
logger.warn("DICOM Request was rejected by the host, reason: 'No reason (provider rejection)'")
when 3
logger.warn("DICOM Request was rejected by the host, reason: 'Abstract syntax not supported'")
when 4
logger.warn("DICOM Request was rejected by the host, reason: 'Transfer syntaxes not supported'")
else
logger.warn("DICOM Request was rejected by the host, reason: 'UNKNOWN (#{result})' (Illegal reason provided)")
end
end
end | [
"def",
"process_result",
"(",
"result",
")",
"unless",
"result",
"==",
"0",
"case",
"result",
"when",
"1",
"logger",
".",
"warn",
"(",
"\"DICOM Request was rejected by the host, reason: 'User-rejection'\"",
")",
"when",
"2",
"logger",
".",
"warn",
"(",
"\"DICOM Request was rejected by the host, reason: 'No reason (provider rejection)'\"",
")",
"when",
"3",
"logger",
".",
"warn",
"(",
"\"DICOM Request was rejected by the host, reason: 'Abstract syntax not supported'\"",
")",
"when",
"4",
"logger",
".",
"warn",
"(",
"\"DICOM Request was rejected by the host, reason: 'Transfer syntaxes not supported'\"",
")",
"else",
"logger",
".",
"warn",
"(",
"\"DICOM Request was rejected by the host, reason: 'UNKNOWN (#{result})' (Illegal reason provided)\"",
")",
"end",
"end",
"end"
]
| Processes the value of the result byte received in the association response.
Prints an explanation if an error is indicated.
=== Notes
A value other than 0 indicates an error.
=== Parameters
* <tt>result</tt> -- Integer. The result code from an association response. | [
"Processes",
"the",
"value",
"of",
"the",
"result",
"byte",
"received",
"in",
"the",
"association",
"response",
".",
"Prints",
"an",
"explanation",
"if",
"an",
"error",
"is",
"indicated",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/link.rb#L1308-L1324 | train |
dicom/ruby-dicom | lib/dicom/link.rb | DICOM.Link.receive_transmission | def receive_transmission(min_length=0)
data = receive_transmission_data
# Check the nature of the received data variable:
if data
# Sometimes the incoming transmission may be broken up into smaller pieces:
# Unless a short answer is expected, we will continue to listen if the first answer was too short:
unless min_length == 0
if data.length < min_length
addition = receive_transmission_data
data = data + addition if addition
end
end
else
# It seems there was no incoming message and the operation timed out.
# Convert the variable to an empty string.
data = ""
end
data
end | ruby | def receive_transmission(min_length=0)
data = receive_transmission_data
# Check the nature of the received data variable:
if data
# Sometimes the incoming transmission may be broken up into smaller pieces:
# Unless a short answer is expected, we will continue to listen if the first answer was too short:
unless min_length == 0
if data.length < min_length
addition = receive_transmission_data
data = data + addition if addition
end
end
else
# It seems there was no incoming message and the operation timed out.
# Convert the variable to an empty string.
data = ""
end
data
end | [
"def",
"receive_transmission",
"(",
"min_length",
"=",
"0",
")",
"data",
"=",
"receive_transmission_data",
"if",
"data",
"unless",
"min_length",
"==",
"0",
"if",
"data",
".",
"length",
"<",
"min_length",
"addition",
"=",
"receive_transmission_data",
"data",
"=",
"data",
"+",
"addition",
"if",
"addition",
"end",
"end",
"else",
"data",
"=",
"\"\"",
"end",
"data",
"end"
]
| Handles an incoming network transmission.
Returns the binary string data received.
=== Notes
If a minimum length has been specified, and a message is received which is shorter than this length,
the method will keep listening for more incoming network packets to append.
=== Parameters
* <tt>min_length</tt> -- Integer. The minimum possible length of a valid incoming transmission. | [
"Handles",
"an",
"incoming",
"network",
"transmission",
".",
"Returns",
"the",
"binary",
"string",
"data",
"received",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/link.rb#L1402-L1420 | train |
dicom/ruby-dicom | lib/dicom/link.rb | DICOM.Link.receive_transmission_data | def receive_transmission_data
data = false
response = IO.select([@session], nil, nil, @timeout)
if response.nil?
logger.error("No answer was received within the specified timeout period. Aborting.")
stop_receiving
else
data = @session.recv(@max_receive_size)
end
data
end | ruby | def receive_transmission_data
data = false
response = IO.select([@session], nil, nil, @timeout)
if response.nil?
logger.error("No answer was received within the specified timeout period. Aborting.")
stop_receiving
else
data = @session.recv(@max_receive_size)
end
data
end | [
"def",
"receive_transmission_data",
"data",
"=",
"false",
"response",
"=",
"IO",
".",
"select",
"(",
"[",
"@session",
"]",
",",
"nil",
",",
"nil",
",",
"@timeout",
")",
"if",
"response",
".",
"nil?",
"logger",
".",
"error",
"(",
"\"No answer was received within the specified timeout period. Aborting.\"",
")",
"stop_receiving",
"else",
"data",
"=",
"@session",
".",
"recv",
"(",
"@max_receive_size",
")",
"end",
"data",
"end"
]
| Receives the data from an incoming network transmission.
Returns the binary string data received. | [
"Receives",
"the",
"data",
"from",
"an",
"incoming",
"network",
"transmission",
".",
"Returns",
"the",
"binary",
"string",
"data",
"received",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/link.rb#L1425-L1435 | train |
dicom/ruby-dicom | lib/dicom/link.rb | DICOM.Link.set_transfer_syntax | def set_transfer_syntax(syntax)
@transfer_syntax = syntax
# Query the library with our particular transfer syntax string:
ts = LIBRARY.uid(@transfer_syntax)
@explicit = ts ? ts.explicit? : true
@data_endian = ts ? ts.big_endian? : false
logger.warn("Invalid/unknown transfer syntax encountered: #{@transfer_syntax} Will try to continue, but errors may occur.") unless ts
end | ruby | def set_transfer_syntax(syntax)
@transfer_syntax = syntax
# Query the library with our particular transfer syntax string:
ts = LIBRARY.uid(@transfer_syntax)
@explicit = ts ? ts.explicit? : true
@data_endian = ts ? ts.big_endian? : false
logger.warn("Invalid/unknown transfer syntax encountered: #{@transfer_syntax} Will try to continue, but errors may occur.") unless ts
end | [
"def",
"set_transfer_syntax",
"(",
"syntax",
")",
"@transfer_syntax",
"=",
"syntax",
"ts",
"=",
"LIBRARY",
".",
"uid",
"(",
"@transfer_syntax",
")",
"@explicit",
"=",
"ts",
"?",
"ts",
".",
"explicit?",
":",
"true",
"@data_endian",
"=",
"ts",
"?",
"ts",
".",
"big_endian?",
":",
"false",
"logger",
".",
"warn",
"(",
"\"Invalid/unknown transfer syntax encountered: #{@transfer_syntax} Will try to continue, but errors may occur.\"",
")",
"unless",
"ts",
"end"
]
| Set instance variables related to a transfer syntax.
=== Parameters
* <tt>syntax</tt> -- A transfer syntax string. | [
"Set",
"instance",
"variables",
"related",
"to",
"a",
"transfer",
"syntax",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/link.rb#L1457-L1464 | train |
dicom/ruby-dicom | lib/dicom/item.rb | DICOM.Item.bin= | 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 | ruby | 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 | [
"def",
"bin",
"=",
"(",
"new_bin",
")",
"raise",
"ArgumentError",
",",
"\"Invalid parameter type. String was expected, got #{new_bin.class}.\"",
"unless",
"new_bin",
".",
"is_a?",
"(",
"String",
")",
"if",
"new_bin",
".",
"length",
".",
"odd?",
"@bin",
"=",
"new_bin",
"+",
"\"\\x00\"",
"else",
"@bin",
"=",
"new_bin",
"end",
"@value",
"=",
"nil",
"@length",
"=",
"@bin",
".",
"length",
"end"
]
| Sets the binary string that the Item will contain.
@param [String] new_bin a binary string of encoded data
@example Insert a custom jpeg in the (encapsulated) pixel data element (in it's first pixel data item)
dcm['7FE0,0010'][1].children.first.bin = jpeg_binary_string | [
"Sets",
"the",
"binary",
"string",
"that",
"the",
"Item",
"will",
"contain",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/item.rb#L79-L89 | train |
dicom/ruby-dicom | lib/dicom/image_processor.rb | DICOM.ImageProcessor.decompress | def decompress(blobs)
raise ArgumentError, "Expected Array or String, got #{blobs.class}." unless [String, Array].include?(blobs.class)
blobs = [blobs] unless blobs.is_a?(Array)
begin
return image_module.decompress(blobs)
rescue
return false
end
end | ruby | def decompress(blobs)
raise ArgumentError, "Expected Array or String, got #{blobs.class}." unless [String, Array].include?(blobs.class)
blobs = [blobs] unless blobs.is_a?(Array)
begin
return image_module.decompress(blobs)
rescue
return false
end
end | [
"def",
"decompress",
"(",
"blobs",
")",
"raise",
"ArgumentError",
",",
"\"Expected Array or String, got #{blobs.class}.\"",
"unless",
"[",
"String",
",",
"Array",
"]",
".",
"include?",
"(",
"blobs",
".",
"class",
")",
"blobs",
"=",
"[",
"blobs",
"]",
"unless",
"blobs",
".",
"is_a?",
"(",
"Array",
")",
"begin",
"return",
"image_module",
".",
"decompress",
"(",
"blobs",
")",
"rescue",
"return",
"false",
"end",
"end"
]
| Creates image objects from one or more compressed, binary string blobs.
@param [Array<String>, String] blobs binary string blob(s) containing compressed pixel data
@return [Array<MagickImage>, FalseClass] - an array of images, or false (if decompression failed) | [
"Creates",
"image",
"objects",
"from",
"one",
"or",
"more",
"compressed",
"binary",
"string",
"blobs",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/image_processor.rb#L13-L21 | train |
dicom/ruby-dicom | lib/dicom/image_processor.rb | DICOM.ImageProcessor.import_pixels | def import_pixels(blob, columns, rows, depth, photometry)
raise ArgumentError, "Expected String, got #{blob.class}." unless blob.is_a?(String)
image_module.import_pixels(blob, columns, rows, depth, photometry)
end | ruby | def import_pixels(blob, columns, rows, depth, photometry)
raise ArgumentError, "Expected String, got #{blob.class}." unless blob.is_a?(String)
image_module.import_pixels(blob, columns, rows, depth, photometry)
end | [
"def",
"import_pixels",
"(",
"blob",
",",
"columns",
",",
"rows",
",",
"depth",
",",
"photometry",
")",
"raise",
"ArgumentError",
",",
"\"Expected String, got #{blob.class}.\"",
"unless",
"blob",
".",
"is_a?",
"(",
"String",
")",
"image_module",
".",
"import_pixels",
"(",
"blob",
",",
"columns",
",",
"rows",
",",
"depth",
",",
"photometry",
")",
"end"
]
| Creates an image object from a binary string blob.
@param [String] blob binary string blob containing pixel data
@param [Integer] columns the number of columns
@param [Integer] rows the number of rows
@param [Integer] depth the bit depth of the encoded pixel data
@param [String] photometry a code describing the photometry of the pixel data (e.g. 'MONOCHROME1' or 'COLOR')
@return [MagickImage] a Magick image object | [
"Creates",
"an",
"image",
"object",
"from",
"a",
"binary",
"string",
"blob",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/image_processor.rb#L43-L46 | train |
calabash/calabash | lib/calabash/location.rb | Calabash.Location.coordinates_for_place | def coordinates_for_place(place_name)
result = Geocoder.search(place_name)
if result.empty?
raise "No result found for '#{place}'"
end
{latitude: result.first.latitude,
longitude: result.first.longitude}
end | ruby | def coordinates_for_place(place_name)
result = Geocoder.search(place_name)
if result.empty?
raise "No result found for '#{place}'"
end
{latitude: result.first.latitude,
longitude: result.first.longitude}
end | [
"def",
"coordinates_for_place",
"(",
"place_name",
")",
"result",
"=",
"Geocoder",
".",
"search",
"(",
"place_name",
")",
"if",
"result",
".",
"empty?",
"raise",
"\"No result found for '#{place}'\"",
"end",
"{",
"latitude",
":",
"result",
".",
"first",
".",
"latitude",
",",
"longitude",
":",
"result",
".",
"first",
".",
"longitude",
"}",
"end"
]
| Get the latitude and longitude for a certain place, resolved via Google
maps api. This hash can be used in `set_location`.
@example
cal.coordinates_for_place('The little mermaid, Copenhagen')
# => {:latitude => 55.6760968, :longitude => 12.5683371}
@return [Hash] Latitude and longitude for the given place
@raise [RuntimeError] If the place cannot be found | [
"Get",
"the",
"latitude",
"and",
"longitude",
"for",
"a",
"certain",
"place",
"resolved",
"via",
"Google",
"maps",
"api",
".",
"This",
"hash",
"can",
"be",
"used",
"in",
"set_location",
"."
]
| fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745 | https://github.com/calabash/calabash/blob/fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745/lib/calabash/location.rb#L39-L48 | train |
dicom/ruby-dicom | lib/dicom/anonymizer.rb | DICOM.Anonymizer.anonymize | def anonymize(dicom)
dicom = Array[dicom] unless dicom.respond_to?(:to_ary)
if @tags.length > 0
prepare_anonymization
dicom.each do |dcm|
anonymize_dcm(dcm.to_dcm)
end
else
logger.warn("No tags have been selected for anonymization. Aborting anonymization.")
end
# Save the audit trail (if used):
@audit_trail.write(@audit_trail_file) if @audit_trail
logger.info("Anonymization complete.")
dicom
end | ruby | def anonymize(dicom)
dicom = Array[dicom] unless dicom.respond_to?(:to_ary)
if @tags.length > 0
prepare_anonymization
dicom.each do |dcm|
anonymize_dcm(dcm.to_dcm)
end
else
logger.warn("No tags have been selected for anonymization. Aborting anonymization.")
end
# Save the audit trail (if used):
@audit_trail.write(@audit_trail_file) if @audit_trail
logger.info("Anonymization complete.")
dicom
end | [
"def",
"anonymize",
"(",
"dicom",
")",
"dicom",
"=",
"Array",
"[",
"dicom",
"]",
"unless",
"dicom",
".",
"respond_to?",
"(",
":to_ary",
")",
"if",
"@tags",
".",
"length",
">",
"0",
"prepare_anonymization",
"dicom",
".",
"each",
"do",
"|",
"dcm",
"|",
"anonymize_dcm",
"(",
"dcm",
".",
"to_dcm",
")",
"end",
"else",
"logger",
".",
"warn",
"(",
"\"No tags have been selected for anonymization. Aborting anonymization.\"",
")",
"end",
"@audit_trail",
".",
"write",
"(",
"@audit_trail_file",
")",
"if",
"@audit_trail",
"logger",
".",
"info",
"(",
"\"Anonymization complete.\"",
")",
"dicom",
"end"
]
| Anonymizes the given DObject or array of DICOM objects with the settings
of this Anonymizer instance.
@param [DObject, Array<DObject>] dicom single or multiple DICOM objects
@return [Array<DObject>] an array of the anonymized DICOM objects | [
"Anonymizes",
"the",
"given",
"DObject",
"or",
"array",
"of",
"DICOM",
"objects",
"with",
"the",
"settings",
"of",
"this",
"Anonymizer",
"instance",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/anonymizer.rb#L141-L155 | train |
dicom/ruby-dicom | lib/dicom/anonymizer.rb | DICOM.Anonymizer.delete_tag | def delete_tag(tag)
raise ArgumentError, "Expected String, got #{tag.class}." unless tag.is_a?(String)
raise ArgumentError, "Expected a valid tag of format 'GGGG,EEEE', got #{tag}." unless tag.tag?
@delete[tag] = true
end | ruby | def delete_tag(tag)
raise ArgumentError, "Expected String, got #{tag.class}." unless tag.is_a?(String)
raise ArgumentError, "Expected a valid tag of format 'GGGG,EEEE', got #{tag}." unless tag.tag?
@delete[tag] = true
end | [
"def",
"delete_tag",
"(",
"tag",
")",
"raise",
"ArgumentError",
",",
"\"Expected String, got #{tag.class}.\"",
"unless",
"tag",
".",
"is_a?",
"(",
"String",
")",
"raise",
"ArgumentError",
",",
"\"Expected a valid tag of format 'GGGG,EEEE', got #{tag}.\"",
"unless",
"tag",
".",
"tag?",
"@delete",
"[",
"tag",
"]",
"=",
"true",
"end"
]
| Specifies that the given tag is to be completely deleted
from the anonymized DICOM objects.
@param [String] tag a data element tag
@example Completely delete the Patient's Name tag from the DICOM files
a.delete_tag('0010,0010') | [
"Specifies",
"that",
"the",
"given",
"tag",
"is",
"to",
"be",
"completely",
"deleted",
"from",
"the",
"anonymized",
"DICOM",
"objects",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/anonymizer.rb#L186-L190 | train |
dicom/ruby-dicom | lib/dicom/anonymizer.rb | DICOM.Anonymizer.set_tag | def set_tag(tag, options={})
raise ArgumentError, "Expected String, got #{tag.class}." unless tag.is_a?(String)
raise ArgumentError, "Expected a valid tag of format 'GGGG,EEEE', got #{tag}." unless tag.tag?
pos = @tags.index(tag)
if pos
# Update existing values:
@values[pos] = options[:value] if options[:value]
@enumerations[pos] = options[:enum] if options[:enum] != nil
else
# Add new elements:
@tags << tag
@values << (options[:value] ? options[:value] : default_value(tag))
@enumerations << (options[:enum] ? options[:enum] : false)
end
end | ruby | def set_tag(tag, options={})
raise ArgumentError, "Expected String, got #{tag.class}." unless tag.is_a?(String)
raise ArgumentError, "Expected a valid tag of format 'GGGG,EEEE', got #{tag}." unless tag.tag?
pos = @tags.index(tag)
if pos
# Update existing values:
@values[pos] = options[:value] if options[:value]
@enumerations[pos] = options[:enum] if options[:enum] != nil
else
# Add new elements:
@tags << tag
@values << (options[:value] ? options[:value] : default_value(tag))
@enumerations << (options[:enum] ? options[:enum] : false)
end
end | [
"def",
"set_tag",
"(",
"tag",
",",
"options",
"=",
"{",
"}",
")",
"raise",
"ArgumentError",
",",
"\"Expected String, got #{tag.class}.\"",
"unless",
"tag",
".",
"is_a?",
"(",
"String",
")",
"raise",
"ArgumentError",
",",
"\"Expected a valid tag of format 'GGGG,EEEE', got #{tag}.\"",
"unless",
"tag",
".",
"tag?",
"pos",
"=",
"@tags",
".",
"index",
"(",
"tag",
")",
"if",
"pos",
"@values",
"[",
"pos",
"]",
"=",
"options",
"[",
":value",
"]",
"if",
"options",
"[",
":value",
"]",
"@enumerations",
"[",
"pos",
"]",
"=",
"options",
"[",
":enum",
"]",
"if",
"options",
"[",
":enum",
"]",
"!=",
"nil",
"else",
"@tags",
"<<",
"tag",
"@values",
"<<",
"(",
"options",
"[",
":value",
"]",
"?",
"options",
"[",
":value",
"]",
":",
"default_value",
"(",
"tag",
")",
")",
"@enumerations",
"<<",
"(",
"options",
"[",
":enum",
"]",
"?",
"options",
"[",
":enum",
"]",
":",
"false",
")",
"end",
"end"
]
| Sets the anonymization settings for the specified tag. If the tag is already present in the list
of tags to be anonymized, its settings are updated, and if not, a new tag entry is created.
@param [String] tag a data element tag
@param [Hash] options the anonymization settings for the specified tag
@option options [String, Integer, Float] :value the replacement value to be used when anonymizing this data element. Defaults to the pre-existing value and '' for new tags.
@option options [String, Integer, Float] :enum specifies if enumeration is to be used for this tag. Defaults to the pre-existing value and false for new tags.
@example Set the anonymization settings of the Patient's Name tag
a.set_tag('0010,0010', :value => 'MrAnonymous', :enum => true) | [
"Sets",
"the",
"anonymization",
"settings",
"for",
"the",
"specified",
"tag",
".",
"If",
"the",
"tag",
"is",
"already",
"present",
"in",
"the",
"list",
"of",
"tags",
"to",
"be",
"anonymized",
"its",
"settings",
"are",
"updated",
"and",
"if",
"not",
"a",
"new",
"tag",
"entry",
"is",
"created",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/anonymizer.rb#L246-L260 | train |
dicom/ruby-dicom | lib/dicom/anonymizer.rb | DICOM.Anonymizer.value | def value(tag)
raise ArgumentError, "Expected String, got #{tag.class}." unless tag.is_a?(String)
raise ArgumentError, "Expected a valid tag of format 'GGGG,EEEE', got #{tag}." unless tag.tag?
pos = @tags.index(tag)
if pos
return @values[pos]
else
logger.warn("The specified tag (#{tag}) was not found in the list of tags to be anonymized.")
return nil
end
end | ruby | def value(tag)
raise ArgumentError, "Expected String, got #{tag.class}." unless tag.is_a?(String)
raise ArgumentError, "Expected a valid tag of format 'GGGG,EEEE', got #{tag}." unless tag.tag?
pos = @tags.index(tag)
if pos
return @values[pos]
else
logger.warn("The specified tag (#{tag}) was not found in the list of tags to be anonymized.")
return nil
end
end | [
"def",
"value",
"(",
"tag",
")",
"raise",
"ArgumentError",
",",
"\"Expected String, got #{tag.class}.\"",
"unless",
"tag",
".",
"is_a?",
"(",
"String",
")",
"raise",
"ArgumentError",
",",
"\"Expected a valid tag of format 'GGGG,EEEE', got #{tag}.\"",
"unless",
"tag",
".",
"tag?",
"pos",
"=",
"@tags",
".",
"index",
"(",
"tag",
")",
"if",
"pos",
"return",
"@values",
"[",
"pos",
"]",
"else",
"logger",
".",
"warn",
"(",
"\"The specified tag (#{tag}) was not found in the list of tags to be anonymized.\"",
")",
"return",
"nil",
"end",
"end"
]
| Gives the value which will be used when anonymizing this tag.
@note If enumeration is selected for a string type tag, a number will be
appended in addition to the string that is returned here.
@param [String] tag a data element tag
@return [String, Integer, Float, NilClass] the replacement value for the specified tag, or nil if the tag is not matched | [
"Gives",
"the",
"value",
"which",
"will",
"be",
"used",
"when",
"anonymizing",
"this",
"tag",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/anonymizer.rb#L278-L288 | train |
dicom/ruby-dicom | lib/dicom/anonymizer.rb | DICOM.Anonymizer.anonymize_dcm | def anonymize_dcm(dcm)
# Extract the data element parents to investigate:
parents = element_parents(dcm)
parents.each do |parent|
# Anonymize the desired tags:
@tags.each_index do |j|
if parent.exists?(@tags[j])
element = parent[@tags[j]]
if element.is_a?(Element)
if @blank
value = ''
elsif @enumeration
old_value = element.value
# Only launch enumeration logic if there is an actual value to the data element:
if old_value
value = enumerated_value(old_value, j)
else
value = ''
end
else
# Use the value that has been set for this tag:
value = @values[j]
end
element.value = value
end
end
end
# Delete elements marked for deletion:
@delete.each_key do |tag|
parent.delete(tag) if parent.exists?(tag)
end
end
# General DICOM object manipulation:
# Add a Patient Identity Removed attribute (as per
# DICOM PS 3.15, Annex E, E.1.1 De-Identifier, point 6):
dcm.add(Element.new('0012,0062', 'YES'))
# Add a De-Identification Method Code Sequence Item:
dcm.add(Sequence.new('0012,0064')) unless dcm.exists?('0012,0064')
i = dcm['0012,0064'].add_item
i.add(Element.new('0012,0063', 'De-identified by the ruby-dicom Anonymizer'))
# FIXME: At some point we should add a set of de-indentification method codes, as per
# DICOM PS 3.16 CID 7050 which corresponds to the settings chosen for the anonymizer.
# Delete the old File Meta Information group (as per
# DICOM PS 3.15, Annex E, E.1.1 De-Identifier, point 7):
dcm.delete_group('0002')
# Handle UIDs if requested:
replace_uids(parents) if @uid
# Delete private tags if indicated:
dcm.delete_private if @delete_private
end | ruby | def anonymize_dcm(dcm)
# Extract the data element parents to investigate:
parents = element_parents(dcm)
parents.each do |parent|
# Anonymize the desired tags:
@tags.each_index do |j|
if parent.exists?(@tags[j])
element = parent[@tags[j]]
if element.is_a?(Element)
if @blank
value = ''
elsif @enumeration
old_value = element.value
# Only launch enumeration logic if there is an actual value to the data element:
if old_value
value = enumerated_value(old_value, j)
else
value = ''
end
else
# Use the value that has been set for this tag:
value = @values[j]
end
element.value = value
end
end
end
# Delete elements marked for deletion:
@delete.each_key do |tag|
parent.delete(tag) if parent.exists?(tag)
end
end
# General DICOM object manipulation:
# Add a Patient Identity Removed attribute (as per
# DICOM PS 3.15, Annex E, E.1.1 De-Identifier, point 6):
dcm.add(Element.new('0012,0062', 'YES'))
# Add a De-Identification Method Code Sequence Item:
dcm.add(Sequence.new('0012,0064')) unless dcm.exists?('0012,0064')
i = dcm['0012,0064'].add_item
i.add(Element.new('0012,0063', 'De-identified by the ruby-dicom Anonymizer'))
# FIXME: At some point we should add a set of de-indentification method codes, as per
# DICOM PS 3.16 CID 7050 which corresponds to the settings chosen for the anonymizer.
# Delete the old File Meta Information group (as per
# DICOM PS 3.15, Annex E, E.1.1 De-Identifier, point 7):
dcm.delete_group('0002')
# Handle UIDs if requested:
replace_uids(parents) if @uid
# Delete private tags if indicated:
dcm.delete_private if @delete_private
end | [
"def",
"anonymize_dcm",
"(",
"dcm",
")",
"parents",
"=",
"element_parents",
"(",
"dcm",
")",
"parents",
".",
"each",
"do",
"|",
"parent",
"|",
"@tags",
".",
"each_index",
"do",
"|",
"j",
"|",
"if",
"parent",
".",
"exists?",
"(",
"@tags",
"[",
"j",
"]",
")",
"element",
"=",
"parent",
"[",
"@tags",
"[",
"j",
"]",
"]",
"if",
"element",
".",
"is_a?",
"(",
"Element",
")",
"if",
"@blank",
"value",
"=",
"''",
"elsif",
"@enumeration",
"old_value",
"=",
"element",
".",
"value",
"if",
"old_value",
"value",
"=",
"enumerated_value",
"(",
"old_value",
",",
"j",
")",
"else",
"value",
"=",
"''",
"end",
"else",
"value",
"=",
"@values",
"[",
"j",
"]",
"end",
"element",
".",
"value",
"=",
"value",
"end",
"end",
"end",
"@delete",
".",
"each_key",
"do",
"|",
"tag",
"|",
"parent",
".",
"delete",
"(",
"tag",
")",
"if",
"parent",
".",
"exists?",
"(",
"tag",
")",
"end",
"end",
"dcm",
".",
"add",
"(",
"Element",
".",
"new",
"(",
"'0012,0062'",
",",
"'YES'",
")",
")",
"dcm",
".",
"add",
"(",
"Sequence",
".",
"new",
"(",
"'0012,0064'",
")",
")",
"unless",
"dcm",
".",
"exists?",
"(",
"'0012,0064'",
")",
"i",
"=",
"dcm",
"[",
"'0012,0064'",
"]",
".",
"add_item",
"i",
".",
"add",
"(",
"Element",
".",
"new",
"(",
"'0012,0063'",
",",
"'De-identified by the ruby-dicom Anonymizer'",
")",
")",
"dcm",
".",
"delete_group",
"(",
"'0002'",
")",
"replace_uids",
"(",
"parents",
")",
"if",
"@uid",
"dcm",
".",
"delete_private",
"if",
"@delete_private",
"end"
]
| Performs anonymization on a DICOM object.
@param [DObject] dcm a DICOM object | [
"Performs",
"anonymization",
"on",
"a",
"DICOM",
"object",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/anonymizer.rb#L298-L347 | train |
dicom/ruby-dicom | lib/dicom/anonymizer.rb | DICOM.Anonymizer.anonymize_file | def anonymize_file(file)
# Temporarily adjust the ruby-dicom log threshold (to suppress messages from the DObject class):
@original_level = logger.level
logger.level = @logger_level
dcm = DObject.read(file)
logger.level = @original_level
anonymize_dcm(dcm)
dcm
end | ruby | def anonymize_file(file)
# Temporarily adjust the ruby-dicom log threshold (to suppress messages from the DObject class):
@original_level = logger.level
logger.level = @logger_level
dcm = DObject.read(file)
logger.level = @original_level
anonymize_dcm(dcm)
dcm
end | [
"def",
"anonymize_file",
"(",
"file",
")",
"@original_level",
"=",
"logger",
".",
"level",
"logger",
".",
"level",
"=",
"@logger_level",
"dcm",
"=",
"DObject",
".",
"read",
"(",
"file",
")",
"logger",
".",
"level",
"=",
"@original_level",
"anonymize_dcm",
"(",
"dcm",
")",
"dcm",
"end"
]
| Performs anonymization of a DICOM file.
@param [String] file a DICOM file path | [
"Performs",
"anonymization",
"of",
"a",
"DICOM",
"file",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/anonymizer.rb#L353-L361 | train |
dicom/ruby-dicom | lib/dicom/anonymizer.rb | DICOM.Anonymizer.default_value | def default_value(tag)
name, vr = LIBRARY.name_and_vr(tag)
conversion = VALUE_CONVERSION[vr]
case conversion
when :to_i then return 0
when :to_f then return 0.0
else
# Assume type is string and return an empty string:
return ''
end
end | ruby | def default_value(tag)
name, vr = LIBRARY.name_and_vr(tag)
conversion = VALUE_CONVERSION[vr]
case conversion
when :to_i then return 0
when :to_f then return 0.0
else
# Assume type is string and return an empty string:
return ''
end
end | [
"def",
"default_value",
"(",
"tag",
")",
"name",
",",
"vr",
"=",
"LIBRARY",
".",
"name_and_vr",
"(",
"tag",
")",
"conversion",
"=",
"VALUE_CONVERSION",
"[",
"vr",
"]",
"case",
"conversion",
"when",
":to_i",
"then",
"return",
"0",
"when",
":to_f",
"then",
"return",
"0.0",
"else",
"return",
"''",
"end",
"end"
]
| Determines a default value to use for anonymizing the given tag.
@param [String] tag a data element tag
@return [String, Integer, Float] the default replacement value for a given tag | [
"Determines",
"a",
"default",
"value",
"to",
"use",
"for",
"anonymizing",
"the",
"given",
"tag",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/anonymizer.rb#L387-L397 | train |
dicom/ruby-dicom | lib/dicom/anonymizer.rb | DICOM.Anonymizer.destination | def destination(dcm)
# Separate the path from the source file string:
file_start = dcm.source.rindex(File.basename(dcm.source))
if file_start == 0
source_dir = "."
else
source_dir = dcm.source[0..(file_start-1)]
end
source_folders = source_dir.split(File::SEPARATOR)
target_folders = @write_path.split(File::SEPARATOR)
# If the first element is the current dir symbol, get rid of it:
source_folders.delete('.')
# Check for equalness of folder names in a range limited by the shortest array:
common_length = [source_folders.length, target_folders.length].min
uncommon_index = nil
common_length.times do |i|
if target_folders[i] != source_folders[i]
uncommon_index = i
break
end
end
# Create the output path by joining the two paths together using the determined index:
append_path = uncommon_index ? source_folders[uncommon_index..-1] : nil
[target_folders, append_path].compact.join(File::SEPARATOR)
end | ruby | def destination(dcm)
# Separate the path from the source file string:
file_start = dcm.source.rindex(File.basename(dcm.source))
if file_start == 0
source_dir = "."
else
source_dir = dcm.source[0..(file_start-1)]
end
source_folders = source_dir.split(File::SEPARATOR)
target_folders = @write_path.split(File::SEPARATOR)
# If the first element is the current dir symbol, get rid of it:
source_folders.delete('.')
# Check for equalness of folder names in a range limited by the shortest array:
common_length = [source_folders.length, target_folders.length].min
uncommon_index = nil
common_length.times do |i|
if target_folders[i] != source_folders[i]
uncommon_index = i
break
end
end
# Create the output path by joining the two paths together using the determined index:
append_path = uncommon_index ? source_folders[uncommon_index..-1] : nil
[target_folders, append_path].compact.join(File::SEPARATOR)
end | [
"def",
"destination",
"(",
"dcm",
")",
"file_start",
"=",
"dcm",
".",
"source",
".",
"rindex",
"(",
"File",
".",
"basename",
"(",
"dcm",
".",
"source",
")",
")",
"if",
"file_start",
"==",
"0",
"source_dir",
"=",
"\".\"",
"else",
"source_dir",
"=",
"dcm",
".",
"source",
"[",
"0",
"..",
"(",
"file_start",
"-",
"1",
")",
"]",
"end",
"source_folders",
"=",
"source_dir",
".",
"split",
"(",
"File",
"::",
"SEPARATOR",
")",
"target_folders",
"=",
"@write_path",
".",
"split",
"(",
"File",
"::",
"SEPARATOR",
")",
"source_folders",
".",
"delete",
"(",
"'.'",
")",
"common_length",
"=",
"[",
"source_folders",
".",
"length",
",",
"target_folders",
".",
"length",
"]",
".",
"min",
"uncommon_index",
"=",
"nil",
"common_length",
".",
"times",
"do",
"|",
"i",
"|",
"if",
"target_folders",
"[",
"i",
"]",
"!=",
"source_folders",
"[",
"i",
"]",
"uncommon_index",
"=",
"i",
"break",
"end",
"end",
"append_path",
"=",
"uncommon_index",
"?",
"source_folders",
"[",
"uncommon_index",
"..",
"-",
"1",
"]",
":",
"nil",
"[",
"target_folders",
",",
"append_path",
"]",
".",
"compact",
".",
"join",
"(",
"File",
"::",
"SEPARATOR",
")",
"end"
]
| Creates a write path for the given DICOM object, based on the object's
original file path and the write_path attribute.
@param [DObject] dcm a DICOM object
@return [String] the destination directory path | [
"Creates",
"a",
"write",
"path",
"for",
"the",
"given",
"DICOM",
"object",
"based",
"on",
"the",
"object",
"s",
"original",
"file",
"path",
"and",
"the",
"write_path",
"attribute",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/anonymizer.rb#L405-L429 | train |
dicom/ruby-dicom | lib/dicom/anonymizer.rb | DICOM.Anonymizer.enumerated_value | def enumerated_value(original, j)
# Is enumeration requested for this tag?
if @enumerations[j]
if @audit_trail
# Check if the UID has been encountered already:
replacement = @audit_trail.replacement(@tags[j], at_value(original))
unless replacement
# This original value has not been encountered yet. Determine the index to use.
index = @audit_trail.records(@tags[j]).length + 1
# Create the replacement value:
if @values[j].is_a?(String)
replacement = @values[j] + index.to_s
else
replacement = @values[j] + index
end
# Add this tag record to the audit trail:
@audit_trail.add_record(@tags[j], at_value(original), replacement)
end
else
# Retrieve earlier used anonymization values:
previous_old = @enum_old_hash[@tags[j]]
previous_new = @enum_new_hash[@tags[j]]
p_index = previous_old.length
if previous_old.index(original) == nil
# Current value has not been encountered before:
replacement = @values[j]+(p_index + 1).to_s
# Store value in array (and hash):
previous_old << original
previous_new << replacement
@enum_old_hash[@tags[j]] = previous_old
@enum_new_hash[@tags[j]] = previous_new
else
# Current value has been observed before:
replacement = previous_new[previous_old.index(original)]
end
end
else
replacement = @values[j]
end
return replacement
end | ruby | def enumerated_value(original, j)
# Is enumeration requested for this tag?
if @enumerations[j]
if @audit_trail
# Check if the UID has been encountered already:
replacement = @audit_trail.replacement(@tags[j], at_value(original))
unless replacement
# This original value has not been encountered yet. Determine the index to use.
index = @audit_trail.records(@tags[j]).length + 1
# Create the replacement value:
if @values[j].is_a?(String)
replacement = @values[j] + index.to_s
else
replacement = @values[j] + index
end
# Add this tag record to the audit trail:
@audit_trail.add_record(@tags[j], at_value(original), replacement)
end
else
# Retrieve earlier used anonymization values:
previous_old = @enum_old_hash[@tags[j]]
previous_new = @enum_new_hash[@tags[j]]
p_index = previous_old.length
if previous_old.index(original) == nil
# Current value has not been encountered before:
replacement = @values[j]+(p_index + 1).to_s
# Store value in array (and hash):
previous_old << original
previous_new << replacement
@enum_old_hash[@tags[j]] = previous_old
@enum_new_hash[@tags[j]] = previous_new
else
# Current value has been observed before:
replacement = previous_new[previous_old.index(original)]
end
end
else
replacement = @values[j]
end
return replacement
end | [
"def",
"enumerated_value",
"(",
"original",
",",
"j",
")",
"if",
"@enumerations",
"[",
"j",
"]",
"if",
"@audit_trail",
"replacement",
"=",
"@audit_trail",
".",
"replacement",
"(",
"@tags",
"[",
"j",
"]",
",",
"at_value",
"(",
"original",
")",
")",
"unless",
"replacement",
"index",
"=",
"@audit_trail",
".",
"records",
"(",
"@tags",
"[",
"j",
"]",
")",
".",
"length",
"+",
"1",
"if",
"@values",
"[",
"j",
"]",
".",
"is_a?",
"(",
"String",
")",
"replacement",
"=",
"@values",
"[",
"j",
"]",
"+",
"index",
".",
"to_s",
"else",
"replacement",
"=",
"@values",
"[",
"j",
"]",
"+",
"index",
"end",
"@audit_trail",
".",
"add_record",
"(",
"@tags",
"[",
"j",
"]",
",",
"at_value",
"(",
"original",
")",
",",
"replacement",
")",
"end",
"else",
"previous_old",
"=",
"@enum_old_hash",
"[",
"@tags",
"[",
"j",
"]",
"]",
"previous_new",
"=",
"@enum_new_hash",
"[",
"@tags",
"[",
"j",
"]",
"]",
"p_index",
"=",
"previous_old",
".",
"length",
"if",
"previous_old",
".",
"index",
"(",
"original",
")",
"==",
"nil",
"replacement",
"=",
"@values",
"[",
"j",
"]",
"+",
"(",
"p_index",
"+",
"1",
")",
".",
"to_s",
"previous_old",
"<<",
"original",
"previous_new",
"<<",
"replacement",
"@enum_old_hash",
"[",
"@tags",
"[",
"j",
"]",
"]",
"=",
"previous_old",
"@enum_new_hash",
"[",
"@tags",
"[",
"j",
"]",
"]",
"=",
"previous_new",
"else",
"replacement",
"=",
"previous_new",
"[",
"previous_old",
".",
"index",
"(",
"original",
")",
"]",
"end",
"end",
"else",
"replacement",
"=",
"@values",
"[",
"j",
"]",
"end",
"return",
"replacement",
"end"
]
| Handles the enumeration for the given data element tag.
If its value has been encountered before, its corresponding enumerated
replacement value is retrieved, and if a new original value is encountered,
a new enumerated replacement value is found by increasing an index by 1.
@param [String, Integer, Float] original the original value of the tag to be anonymized
@param [Integer] j the index of this tag in the tag-related instance arrays
@return [String, Integer, Float] the replacement value which is used for the anonymization of the tag | [
"Handles",
"the",
"enumeration",
"for",
"the",
"given",
"data",
"element",
"tag",
".",
"If",
"its",
"value",
"has",
"been",
"encountered",
"before",
"its",
"corresponding",
"enumerated",
"replacement",
"value",
"is",
"retrieved",
"and",
"if",
"a",
"new",
"original",
"value",
"is",
"encountered",
"a",
"new",
"enumerated",
"replacement",
"value",
"is",
"found",
"by",
"increasing",
"an",
"index",
"by",
"1",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/anonymizer.rb#L477-L517 | train |
dicom/ruby-dicom | lib/dicom/anonymizer.rb | DICOM.Anonymizer.replace_uids | def replace_uids(parents)
parents.each do |parent|
parent.each_element do |element|
if element.vr == ('UI') and !@static_uids[element.tag]
original = element.value
if original && original.length > 0
# We have a UID value, go ahead and replace it:
if @audit_trail
# Check if the UID has been encountered already:
replacement = @audit_trail.replacement('uids', original)
unless replacement
# The UID has not been stored previously. Generate a new one:
replacement = DICOM.generate_uid(@uid_root, prefix(element.tag))
# Add this tag record to the audit trail:
@audit_trail.add_record('uids', original, replacement)
end
# Replace the UID in the DICOM object:
element.value = replacement
else
# We don't care about preserving UID relations. Just insert a custom UID:
element.value = DICOM.generate_uid(@uid_root, prefix(element.tag))
end
end
end
end
end
end | ruby | def replace_uids(parents)
parents.each do |parent|
parent.each_element do |element|
if element.vr == ('UI') and !@static_uids[element.tag]
original = element.value
if original && original.length > 0
# We have a UID value, go ahead and replace it:
if @audit_trail
# Check if the UID has been encountered already:
replacement = @audit_trail.replacement('uids', original)
unless replacement
# The UID has not been stored previously. Generate a new one:
replacement = DICOM.generate_uid(@uid_root, prefix(element.tag))
# Add this tag record to the audit trail:
@audit_trail.add_record('uids', original, replacement)
end
# Replace the UID in the DICOM object:
element.value = replacement
else
# We don't care about preserving UID relations. Just insert a custom UID:
element.value = DICOM.generate_uid(@uid_root, prefix(element.tag))
end
end
end
end
end
end | [
"def",
"replace_uids",
"(",
"parents",
")",
"parents",
".",
"each",
"do",
"|",
"parent",
"|",
"parent",
".",
"each_element",
"do",
"|",
"element",
"|",
"if",
"element",
".",
"vr",
"==",
"(",
"'UI'",
")",
"and",
"!",
"@static_uids",
"[",
"element",
".",
"tag",
"]",
"original",
"=",
"element",
".",
"value",
"if",
"original",
"&&",
"original",
".",
"length",
">",
"0",
"if",
"@audit_trail",
"replacement",
"=",
"@audit_trail",
".",
"replacement",
"(",
"'uids'",
",",
"original",
")",
"unless",
"replacement",
"replacement",
"=",
"DICOM",
".",
"generate_uid",
"(",
"@uid_root",
",",
"prefix",
"(",
"element",
".",
"tag",
")",
")",
"@audit_trail",
".",
"add_record",
"(",
"'uids'",
",",
"original",
",",
"replacement",
")",
"end",
"element",
".",
"value",
"=",
"replacement",
"else",
"element",
".",
"value",
"=",
"DICOM",
".",
"generate_uid",
"(",
"@uid_root",
",",
"prefix",
"(",
"element",
".",
"tag",
")",
")",
"end",
"end",
"end",
"end",
"end",
"end"
]
| Replaces the UIDs of the given DICOM object.
@note Empty UIDs are ignored (we don't generate new UIDs for these).
@note If AuditTrail is set, the relationship between old and new UIDs are preserved,
and the relations between files in a study/series should remain valid.
@param [Array<DObject, Item>] parents dicom parent objects who's child elements will be investigated | [
"Replaces",
"the",
"UIDs",
"of",
"the",
"given",
"DICOM",
"object",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/anonymizer.rb#L550-L576 | train |
dicom/ruby-dicom | lib/dicom/anonymizer.rb | DICOM.Anonymizer.set_defaults | def set_defaults
# Some UIDs should not be remapped even if uid anonymization has been requested:
@static_uids = {
# Private related:
'0002,0100' => true,
'0004,1432' => true,
# Coding scheme related:
'0008,010C' => true,
'0008,010D' => true,
# Transfer syntax related:
'0002,0010' => true,
'0400,0010' => true,
'0400,0510' => true,
'0004,1512' => true,
# SOP class related:
'0000,0002' => true,
'0000,0003' => true,
'0002,0002' => true,
'0004,1510' => true,
'0004,151A' => true,
'0008,0016' => true,
'0008,001A' => true,
'0008,001B' => true,
'0008,0062' => true,
'0008,1150' => true,
'0008,115A' => true
}
# Sets up default tags that will be anonymized, along with default replacement values and enumeration settings.
# This data is stored in 3 separate instance arrays for tags, values and enumeration.
data = [
['0008,0012', '20000101', false], # Instance Creation Date
['0008,0013', '000000.00', false], # Instance Creation Time
['0008,0020', '20000101', false], # Study Date
['0008,0021', '20000101', false], # Series Date
['0008,0022', '20000101', false], # Acquisition Date
['0008,0023', '20000101', false], # Image Date
['0008,0030', '000000.00', false], # Study Time
['0008,0031', '000000.00', false], # Series Time
['0008,0032', '000000.00', false], # Acquisition Time
['0008,0033', '000000.00', false], # Image Time
['0008,0050', '', true], # Accession Number
['0008,0080', 'Institution', true], # Institution name
['0008,0081', 'Address', true], # Institution Address
['0008,0090', 'Physician', true], # Referring Physician's name
['0008,1010', 'Station', true], # Station name
['0008,1040', 'Department', true], # Institutional Department name
['0008,1070', 'Operator', true], # Operator's Name
['0010,0010', 'Patient', true], # Patient's name
['0010,0020', 'ID', true], # Patient's ID
['0010,0030', '20000101', false], # Patient's Birth Date
['0010,0040', 'O', false], # Patient's Sex
['0010,1010', '', false], # Patient's Age
['0020,4000', '', false], # Image Comments
].transpose
@tags = data[0]
@values = data[1]
@enumerations = data[2]
# Tags to be deleted completely during anonymization:
@delete = Hash.new
end | ruby | def set_defaults
# Some UIDs should not be remapped even if uid anonymization has been requested:
@static_uids = {
# Private related:
'0002,0100' => true,
'0004,1432' => true,
# Coding scheme related:
'0008,010C' => true,
'0008,010D' => true,
# Transfer syntax related:
'0002,0010' => true,
'0400,0010' => true,
'0400,0510' => true,
'0004,1512' => true,
# SOP class related:
'0000,0002' => true,
'0000,0003' => true,
'0002,0002' => true,
'0004,1510' => true,
'0004,151A' => true,
'0008,0016' => true,
'0008,001A' => true,
'0008,001B' => true,
'0008,0062' => true,
'0008,1150' => true,
'0008,115A' => true
}
# Sets up default tags that will be anonymized, along with default replacement values and enumeration settings.
# This data is stored in 3 separate instance arrays for tags, values and enumeration.
data = [
['0008,0012', '20000101', false], # Instance Creation Date
['0008,0013', '000000.00', false], # Instance Creation Time
['0008,0020', '20000101', false], # Study Date
['0008,0021', '20000101', false], # Series Date
['0008,0022', '20000101', false], # Acquisition Date
['0008,0023', '20000101', false], # Image Date
['0008,0030', '000000.00', false], # Study Time
['0008,0031', '000000.00', false], # Series Time
['0008,0032', '000000.00', false], # Acquisition Time
['0008,0033', '000000.00', false], # Image Time
['0008,0050', '', true], # Accession Number
['0008,0080', 'Institution', true], # Institution name
['0008,0081', 'Address', true], # Institution Address
['0008,0090', 'Physician', true], # Referring Physician's name
['0008,1010', 'Station', true], # Station name
['0008,1040', 'Department', true], # Institutional Department name
['0008,1070', 'Operator', true], # Operator's Name
['0010,0010', 'Patient', true], # Patient's name
['0010,0020', 'ID', true], # Patient's ID
['0010,0030', '20000101', false], # Patient's Birth Date
['0010,0040', 'O', false], # Patient's Sex
['0010,1010', '', false], # Patient's Age
['0020,4000', '', false], # Image Comments
].transpose
@tags = data[0]
@values = data[1]
@enumerations = data[2]
# Tags to be deleted completely during anonymization:
@delete = Hash.new
end | [
"def",
"set_defaults",
"@static_uids",
"=",
"{",
"'0002,0100'",
"=>",
"true",
",",
"'0004,1432'",
"=>",
"true",
",",
"'0008,010C'",
"=>",
"true",
",",
"'0008,010D'",
"=>",
"true",
",",
"'0002,0010'",
"=>",
"true",
",",
"'0400,0010'",
"=>",
"true",
",",
"'0400,0510'",
"=>",
"true",
",",
"'0004,1512'",
"=>",
"true",
",",
"'0000,0002'",
"=>",
"true",
",",
"'0000,0003'",
"=>",
"true",
",",
"'0002,0002'",
"=>",
"true",
",",
"'0004,1510'",
"=>",
"true",
",",
"'0004,151A'",
"=>",
"true",
",",
"'0008,0016'",
"=>",
"true",
",",
"'0008,001A'",
"=>",
"true",
",",
"'0008,001B'",
"=>",
"true",
",",
"'0008,0062'",
"=>",
"true",
",",
"'0008,1150'",
"=>",
"true",
",",
"'0008,115A'",
"=>",
"true",
"}",
"data",
"=",
"[",
"[",
"'0008,0012'",
",",
"'20000101'",
",",
"false",
"]",
",",
"[",
"'0008,0013'",
",",
"'000000.00'",
",",
"false",
"]",
",",
"[",
"'0008,0020'",
",",
"'20000101'",
",",
"false",
"]",
",",
"[",
"'0008,0021'",
",",
"'20000101'",
",",
"false",
"]",
",",
"[",
"'0008,0022'",
",",
"'20000101'",
",",
"false",
"]",
",",
"[",
"'0008,0023'",
",",
"'20000101'",
",",
"false",
"]",
",",
"[",
"'0008,0030'",
",",
"'000000.00'",
",",
"false",
"]",
",",
"[",
"'0008,0031'",
",",
"'000000.00'",
",",
"false",
"]",
",",
"[",
"'0008,0032'",
",",
"'000000.00'",
",",
"false",
"]",
",",
"[",
"'0008,0033'",
",",
"'000000.00'",
",",
"false",
"]",
",",
"[",
"'0008,0050'",
",",
"''",
",",
"true",
"]",
",",
"[",
"'0008,0080'",
",",
"'Institution'",
",",
"true",
"]",
",",
"[",
"'0008,0081'",
",",
"'Address'",
",",
"true",
"]",
",",
"[",
"'0008,0090'",
",",
"'Physician'",
",",
"true",
"]",
",",
"[",
"'0008,1010'",
",",
"'Station'",
",",
"true",
"]",
",",
"[",
"'0008,1040'",
",",
"'Department'",
",",
"true",
"]",
",",
"[",
"'0008,1070'",
",",
"'Operator'",
",",
"true",
"]",
",",
"[",
"'0010,0010'",
",",
"'Patient'",
",",
"true",
"]",
",",
"[",
"'0010,0020'",
",",
"'ID'",
",",
"true",
"]",
",",
"[",
"'0010,0030'",
",",
"'20000101'",
",",
"false",
"]",
",",
"[",
"'0010,0040'",
",",
"'O'",
",",
"false",
"]",
",",
"[",
"'0010,1010'",
",",
"''",
",",
"false",
"]",
",",
"[",
"'0020,4000'",
",",
"''",
",",
"false",
"]",
",",
"]",
".",
"transpose",
"@tags",
"=",
"data",
"[",
"0",
"]",
"@values",
"=",
"data",
"[",
"1",
"]",
"@enumerations",
"=",
"data",
"[",
"2",
"]",
"@delete",
"=",
"Hash",
".",
"new",
"end"
]
| Sets up some default information variables that are used by the Anonymizer. | [
"Sets",
"up",
"some",
"default",
"information",
"variables",
"that",
"are",
"used",
"by",
"the",
"Anonymizer",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/anonymizer.rb#L580-L639 | train |
dicom/ruby-dicom | lib/dicom/anonymizer.rb | DICOM.Anonymizer.write | def write(dcm)
if @write_path
# The DICOM object is to be written to a separate directory. If the
# original and the new directories have a common root, this is taken into
# consideration when determining the object's write path:
path = destination(dcm)
if @random_file_name
file_name = "#{SecureRandom.hex(16)}.dcm"
else
file_name = File.basename(dcm.source)
end
dcm.write(File.join(path, file_name))
else
# The original DICOM file is overwritten with the anonymized DICOM object:
dcm.write(dcm.source)
end
end | ruby | def write(dcm)
if @write_path
# The DICOM object is to be written to a separate directory. If the
# original and the new directories have a common root, this is taken into
# consideration when determining the object's write path:
path = destination(dcm)
if @random_file_name
file_name = "#{SecureRandom.hex(16)}.dcm"
else
file_name = File.basename(dcm.source)
end
dcm.write(File.join(path, file_name))
else
# The original DICOM file is overwritten with the anonymized DICOM object:
dcm.write(dcm.source)
end
end | [
"def",
"write",
"(",
"dcm",
")",
"if",
"@write_path",
"path",
"=",
"destination",
"(",
"dcm",
")",
"if",
"@random_file_name",
"file_name",
"=",
"\"#{SecureRandom.hex(16)}.dcm\"",
"else",
"file_name",
"=",
"File",
".",
"basename",
"(",
"dcm",
".",
"source",
")",
"end",
"dcm",
".",
"write",
"(",
"File",
".",
"join",
"(",
"path",
",",
"file_name",
")",
")",
"else",
"dcm",
".",
"write",
"(",
"dcm",
".",
"source",
")",
"end",
"end"
]
| Writes a DICOM object to file.
@param [DObject] dcm a DICOM object | [
"Writes",
"a",
"DICOM",
"object",
"to",
"file",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/anonymizer.rb#L657-L673 | train |
dicom/ruby-dicom | lib/dicom/element.rb | DICOM.Element.value= | def value=(new_value)
if VALUE_CONVERSION[@vr] == :to_s
# Unless this is actually the Character Set data element,
# get the character set (note that it may not be available):
character_set = (@tag != '0008,0005' && top_parent.is_a?(DObject)) ? top_parent.value('0008,0005') : nil
# Convert to [DObject encoding] from [input string encoding]:
# In most cases the DObject encoding is IS0-8859-1 (ISO_IR 100), but if
# it is not specified in the DICOM object, or if the specified string
# is not recognized, ASCII-8BIT is assumed.
@value = new_value.to_s.encode(ENCODING_NAME[character_set], new_value.to_s.encoding.name)
@bin = encode(@value)
else
# We may have an array (of numbers) which needs to be passed directly to
# the encode method instead of being forced into a numerical:
if new_value.is_a?(Array)
@value = new_value
@bin = encode(@value)
else
@value = new_value.send(VALUE_CONVERSION[@vr])
@bin = encode(@value)
end
end
@length = @bin.length
end | ruby | def value=(new_value)
if VALUE_CONVERSION[@vr] == :to_s
# Unless this is actually the Character Set data element,
# get the character set (note that it may not be available):
character_set = (@tag != '0008,0005' && top_parent.is_a?(DObject)) ? top_parent.value('0008,0005') : nil
# Convert to [DObject encoding] from [input string encoding]:
# In most cases the DObject encoding is IS0-8859-1 (ISO_IR 100), but if
# it is not specified in the DICOM object, or if the specified string
# is not recognized, ASCII-8BIT is assumed.
@value = new_value.to_s.encode(ENCODING_NAME[character_set], new_value.to_s.encoding.name)
@bin = encode(@value)
else
# We may have an array (of numbers) which needs to be passed directly to
# the encode method instead of being forced into a numerical:
if new_value.is_a?(Array)
@value = new_value
@bin = encode(@value)
else
@value = new_value.send(VALUE_CONVERSION[@vr])
@bin = encode(@value)
end
end
@length = @bin.length
end | [
"def",
"value",
"=",
"(",
"new_value",
")",
"if",
"VALUE_CONVERSION",
"[",
"@vr",
"]",
"==",
":to_s",
"character_set",
"=",
"(",
"@tag",
"!=",
"'0008,0005'",
"&&",
"top_parent",
".",
"is_a?",
"(",
"DObject",
")",
")",
"?",
"top_parent",
".",
"value",
"(",
"'0008,0005'",
")",
":",
"nil",
"@value",
"=",
"new_value",
".",
"to_s",
".",
"encode",
"(",
"ENCODING_NAME",
"[",
"character_set",
"]",
",",
"new_value",
".",
"to_s",
".",
"encoding",
".",
"name",
")",
"@bin",
"=",
"encode",
"(",
"@value",
")",
"else",
"if",
"new_value",
".",
"is_a?",
"(",
"Array",
")",
"@value",
"=",
"new_value",
"@bin",
"=",
"encode",
"(",
"@value",
")",
"else",
"@value",
"=",
"new_value",
".",
"send",
"(",
"VALUE_CONVERSION",
"[",
"@vr",
"]",
")",
"@bin",
"=",
"encode",
"(",
"@value",
")",
"end",
"end",
"@length",
"=",
"@bin",
".",
"length",
"end"
]
| Sets the value of the Element instance.
In addition to updating the value attribute, the specified value is encoded to binary
and used to update the Element's bin and length attributes too.
@note The specified value must be of a type that is compatible with the Element's value representation (vr).
@param [String, Integer, Float, Array] new_value a formatted value that is assigned to the element | [
"Sets",
"the",
"value",
"of",
"the",
"Element",
"instance",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/element.rb#L231-L254 | train |
calabash/calabash | lib/calabash/ios/console_helpers.rb | Calabash.ConsoleHelpers.console_attach | def console_attach(uia_strategy=nil)
Calabash::Application.default = Calabash::IOS::Application.default_from_environment
identifier = Calabash::IOS::Device.default_identifier_for_application(Calabash::Application.default)
server = Calabash::IOS::Server.default
device = Calabash::IOS::Device.new(identifier, server)
Calabash::Device.default = device
begin
Calabash::Internal.with_current_target(required_os: :ios) {|target| target.ensure_test_server_ready({:timeout => 4})}
rescue RuntimeError => e
if e.to_s == 'Calabash server did not respond'
raise RuntimeError, 'You can only attach to a running Calabash iOS App'
else
raise e
end
end
run_loop_device = device.send(:run_loop_device)
result = Calabash::Internal.with_current_target(required_os: :ios) {|target| target.send(:attach_to_run_loop, run_loop_device, uia_strategy)}
result[:application] = Calabash::Application.default
result
end | ruby | def console_attach(uia_strategy=nil)
Calabash::Application.default = Calabash::IOS::Application.default_from_environment
identifier = Calabash::IOS::Device.default_identifier_for_application(Calabash::Application.default)
server = Calabash::IOS::Server.default
device = Calabash::IOS::Device.new(identifier, server)
Calabash::Device.default = device
begin
Calabash::Internal.with_current_target(required_os: :ios) {|target| target.ensure_test_server_ready({:timeout => 4})}
rescue RuntimeError => e
if e.to_s == 'Calabash server did not respond'
raise RuntimeError, 'You can only attach to a running Calabash iOS App'
else
raise e
end
end
run_loop_device = device.send(:run_loop_device)
result = Calabash::Internal.with_current_target(required_os: :ios) {|target| target.send(:attach_to_run_loop, run_loop_device, uia_strategy)}
result[:application] = Calabash::Application.default
result
end | [
"def",
"console_attach",
"(",
"uia_strategy",
"=",
"nil",
")",
"Calabash",
"::",
"Application",
".",
"default",
"=",
"Calabash",
"::",
"IOS",
"::",
"Application",
".",
"default_from_environment",
"identifier",
"=",
"Calabash",
"::",
"IOS",
"::",
"Device",
".",
"default_identifier_for_application",
"(",
"Calabash",
"::",
"Application",
".",
"default",
")",
"server",
"=",
"Calabash",
"::",
"IOS",
"::",
"Server",
".",
"default",
"device",
"=",
"Calabash",
"::",
"IOS",
"::",
"Device",
".",
"new",
"(",
"identifier",
",",
"server",
")",
"Calabash",
"::",
"Device",
".",
"default",
"=",
"device",
"begin",
"Calabash",
"::",
"Internal",
".",
"with_current_target",
"(",
"required_os",
":",
":ios",
")",
"{",
"|",
"target",
"|",
"target",
".",
"ensure_test_server_ready",
"(",
"{",
":timeout",
"=>",
"4",
"}",
")",
"}",
"rescue",
"RuntimeError",
"=>",
"e",
"if",
"e",
".",
"to_s",
"==",
"'Calabash server did not respond'",
"raise",
"RuntimeError",
",",
"'You can only attach to a running Calabash iOS App'",
"else",
"raise",
"e",
"end",
"end",
"run_loop_device",
"=",
"device",
".",
"send",
"(",
":run_loop_device",
")",
"result",
"=",
"Calabash",
"::",
"Internal",
".",
"with_current_target",
"(",
"required_os",
":",
":ios",
")",
"{",
"|",
"target",
"|",
"target",
".",
"send",
"(",
":attach_to_run_loop",
",",
"run_loop_device",
",",
"uia_strategy",
")",
"}",
"result",
"[",
":application",
"]",
"=",
"Calabash",
"::",
"Application",
".",
"default",
"result",
"end"
]
| Attach the current Calabash run-loop to a console.
@example
You have encountered a failing cucumber Scenario.
You open the console and want to start investigating the cause of the failure.
Use
> console_attach
to connect to the current run-loop so you can perform gestures.
@param [Symbol] uia_strategy Optionally specify the uia strategy, which
can be one of :shared_element, :preferences, :host. If you don't
know which to choose, don't specify one and calabash will try deduce
the correct strategy to use based on the environment variables used
when starting the console.
@return [Hash] The hash will contain the current device, the path to the
current application, and the run-loop strategy.
@raise [RuntimeError] If the app is not running. | [
"Attach",
"the",
"current",
"Calabash",
"run",
"-",
"loop",
"to",
"a",
"console",
"."
]
| fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745 | https://github.com/calabash/calabash/blob/fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745/lib/calabash/ios/console_helpers.rb#L48-L71 | train |
calabash/calabash | lib/calabash/device.rb | Calabash.Device.pan_between | def pan_between(query_from, query_to, options={})
ensure_query_class_or_nil(query_from)
ensure_query_class_or_nil(query_to)
gesture_options = options.dup
gesture_options[:timeout] ||= Calabash::Gestures::DEFAULT_GESTURE_WAIT_TIMEOUT
_pan_between(query_from, query_to, gesture_options)
end | ruby | def pan_between(query_from, query_to, options={})
ensure_query_class_or_nil(query_from)
ensure_query_class_or_nil(query_to)
gesture_options = options.dup
gesture_options[:timeout] ||= Calabash::Gestures::DEFAULT_GESTURE_WAIT_TIMEOUT
_pan_between(query_from, query_to, gesture_options)
end | [
"def",
"pan_between",
"(",
"query_from",
",",
"query_to",
",",
"options",
"=",
"{",
"}",
")",
"ensure_query_class_or_nil",
"(",
"query_from",
")",
"ensure_query_class_or_nil",
"(",
"query_to",
")",
"gesture_options",
"=",
"options",
".",
"dup",
"gesture_options",
"[",
":timeout",
"]",
"||=",
"Calabash",
"::",
"Gestures",
"::",
"DEFAULT_GESTURE_WAIT_TIMEOUT",
"_pan_between",
"(",
"query_from",
",",
"query_to",
",",
"gesture_options",
")",
"end"
]
| Performs a `pan` between two elements.
@see Calabash::Gestures#pan_between
@!visibility private | [
"Performs",
"a",
"pan",
"between",
"two",
"elements",
"."
]
| fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745 | https://github.com/calabash/calabash/blob/fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745/lib/calabash/device.rb#L182-L191 | train |
calabash/calabash | lib/calabash/device.rb | Calabash.Device.flick_between | def flick_between(query_from, query_to, options={})
ensure_query_class_or_nil(query_from)
ensure_query_class_or_nil(query_to)
gesture_options = options.dup
gesture_options[:timeout] ||= Calabash::Gestures::DEFAULT_GESTURE_WAIT_TIMEOUT
_flick_between(query_from, query_to, gesture_options)
end | ruby | def flick_between(query_from, query_to, options={})
ensure_query_class_or_nil(query_from)
ensure_query_class_or_nil(query_to)
gesture_options = options.dup
gesture_options[:timeout] ||= Calabash::Gestures::DEFAULT_GESTURE_WAIT_TIMEOUT
_flick_between(query_from, query_to, gesture_options)
end | [
"def",
"flick_between",
"(",
"query_from",
",",
"query_to",
",",
"options",
"=",
"{",
"}",
")",
"ensure_query_class_or_nil",
"(",
"query_from",
")",
"ensure_query_class_or_nil",
"(",
"query_to",
")",
"gesture_options",
"=",
"options",
".",
"dup",
"gesture_options",
"[",
":timeout",
"]",
"||=",
"Calabash",
"::",
"Gestures",
"::",
"DEFAULT_GESTURE_WAIT_TIMEOUT",
"_flick_between",
"(",
"query_from",
",",
"query_to",
",",
"gesture_options",
")",
"end"
]
| Performs a `flick` between two elements.
@!visibility private | [
"Performs",
"a",
"flick",
"between",
"two",
"elements",
"."
]
| fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745 | https://github.com/calabash/calabash/blob/fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745/lib/calabash/device.rb#L195-L204 | train |
calabash/calabash | lib/calabash/web.rb | Calabash.Web.evaluate_javascript_in | def evaluate_javascript_in(query, javascript)
wait_for_view(query,
timeout: Calabash::Gestures::DEFAULT_GESTURE_WAIT_TIMEOUT)
_evaluate_javascript_in(query, javascript)
end | ruby | def evaluate_javascript_in(query, javascript)
wait_for_view(query,
timeout: Calabash::Gestures::DEFAULT_GESTURE_WAIT_TIMEOUT)
_evaluate_javascript_in(query, javascript)
end | [
"def",
"evaluate_javascript_in",
"(",
"query",
",",
"javascript",
")",
"wait_for_view",
"(",
"query",
",",
"timeout",
":",
"Calabash",
"::",
"Gestures",
"::",
"DEFAULT_GESTURE_WAIT_TIMEOUT",
")",
"_evaluate_javascript_in",
"(",
"query",
",",
"javascript",
")",
"end"
]
| Evaluate javascript in a Web View. On iOS, an implicit return is
inserted, on Android an explicit return is needed.
@example
# iOS
cal.evaluate_javascript_in("UIWebView", "2+2")
# Android
cal.evaluate_javascript_in("WebView", "return 2+2")
@example
# iOS
cal.evaluate_javascript_in("WKWebView",
"document.body.style.backgroundColor = 'red';")
# Android
cal.evaluate_javascript_in("XWalkContent",
"document.body.style.backgroundColor = 'red';")
@note No error will be raised if the javascript given is invalid, or
throws an exception.
@param [String, Hash, Calabash::Query] query Query that matches the
webview
@param [String] javascript The javascript to evaluate
@raise ViewNotFoundError If no views are found matching `query` | [
"Evaluate",
"javascript",
"in",
"a",
"Web",
"View",
".",
"On",
"iOS",
"an",
"implicit",
"return",
"is",
"inserted",
"on",
"Android",
"an",
"explicit",
"return",
"is",
"needed",
"."
]
| fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745 | https://github.com/calabash/calabash/blob/fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745/lib/calabash/web.rb#L30-L35 | train |
calabash/calabash | lib/calabash/text.rb | Calabash.Text.wait_for_keyboard | def wait_for_keyboard(timeout: nil)
keyboard_timeout = keyboard_wait_timeout(timeout)
message = "Timed out after #{keyboard_timeout} seconds waiting for the keyboard to appear"
wait_for(message, timeout: keyboard_timeout) do
keyboard_visible?
end
end | ruby | def wait_for_keyboard(timeout: nil)
keyboard_timeout = keyboard_wait_timeout(timeout)
message = "Timed out after #{keyboard_timeout} seconds waiting for the keyboard to appear"
wait_for(message, timeout: keyboard_timeout) do
keyboard_visible?
end
end | [
"def",
"wait_for_keyboard",
"(",
"timeout",
":",
"nil",
")",
"keyboard_timeout",
"=",
"keyboard_wait_timeout",
"(",
"timeout",
")",
"message",
"=",
"\"Timed out after #{keyboard_timeout} seconds waiting for the keyboard to appear\"",
"wait_for",
"(",
"message",
",",
"timeout",
":",
"keyboard_timeout",
")",
"do",
"keyboard_visible?",
"end",
"end"
]
| Waits for a keyboard to appear.
@see Calabash::Wait.default_options
@param [Number] timeout How long to wait for the keyboard.
@raise [Calabash::Wait::TimeoutError] Raises error if no keyboard
appears. | [
"Waits",
"for",
"a",
"keyboard",
"to",
"appear",
"."
]
| fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745 | https://github.com/calabash/calabash/blob/fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745/lib/calabash/text.rb#L125-L131 | train |
calabash/calabash | lib/calabash/text.rb | Calabash.Text.wait_for_no_keyboard | def wait_for_no_keyboard(timeout: nil)
keyboard_timeout = keyboard_wait_timeout(timeout)
message = "Timed out after #{keyboard_timeout} seconds waiting for the keyboard to disappear"
wait_for(message, timeout: keyboard_timeout) do
!keyboard_visible?
end
end | ruby | def wait_for_no_keyboard(timeout: nil)
keyboard_timeout = keyboard_wait_timeout(timeout)
message = "Timed out after #{keyboard_timeout} seconds waiting for the keyboard to disappear"
wait_for(message, timeout: keyboard_timeout) do
!keyboard_visible?
end
end | [
"def",
"wait_for_no_keyboard",
"(",
"timeout",
":",
"nil",
")",
"keyboard_timeout",
"=",
"keyboard_wait_timeout",
"(",
"timeout",
")",
"message",
"=",
"\"Timed out after #{keyboard_timeout} seconds waiting for the keyboard to disappear\"",
"wait_for",
"(",
"message",
",",
"timeout",
":",
"keyboard_timeout",
")",
"do",
"!",
"keyboard_visible?",
"end",
"end"
]
| Waits for the keyboard to disappear.
@see Calabash::Wait.default_options
@param [Number] timeout How log to wait for the keyboard to disappear.
@raise [Calabash::Wait::TimeoutError] Raises error if any keyboard is
visible after the `timeout`. | [
"Waits",
"for",
"the",
"keyboard",
"to",
"disappear",
"."
]
| fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745 | https://github.com/calabash/calabash/blob/fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745/lib/calabash/text.rb#L140-L146 | train |
dicom/ruby-dicom | lib/dicom/d_client.rb | DICOM.DClient.find_series | def find_series(query_params={})
# Study Root Query/Retrieve Information Model - FIND:
set_default_presentation_context("1.2.840.10008.5.1.4.1.2.2.1")
# Every query attribute with a value != nil (required) will be sent in the dicom query.
# The query parameters with nil-value (optional) are left out unless specified.
default_query_params = {
"0008,0052" => "SERIES", # Query/Retrieve Level: "SERIES"
"0008,0060" => "", # Modality
"0020,000E" => "", # Series Instance UID
"0020,0011" => "" # Series Number
}
# Raising an error if a non-tag query attribute is used:
query_params.keys.each do |tag|
raise ArgumentError, "The supplied tag (#{tag}) is not valid. It must be a string of the form 'GGGG,EEEE'." unless tag.is_a?(String) && tag.tag?
end
# Set up the query parameters and carry out the C-FIND:
set_data_elements(default_query_params.merge(query_params))
perform_find
return @data_results
end | ruby | def find_series(query_params={})
# Study Root Query/Retrieve Information Model - FIND:
set_default_presentation_context("1.2.840.10008.5.1.4.1.2.2.1")
# Every query attribute with a value != nil (required) will be sent in the dicom query.
# The query parameters with nil-value (optional) are left out unless specified.
default_query_params = {
"0008,0052" => "SERIES", # Query/Retrieve Level: "SERIES"
"0008,0060" => "", # Modality
"0020,000E" => "", # Series Instance UID
"0020,0011" => "" # Series Number
}
# Raising an error if a non-tag query attribute is used:
query_params.keys.each do |tag|
raise ArgumentError, "The supplied tag (#{tag}) is not valid. It must be a string of the form 'GGGG,EEEE'." unless tag.is_a?(String) && tag.tag?
end
# Set up the query parameters and carry out the C-FIND:
set_data_elements(default_query_params.merge(query_params))
perform_find
return @data_results
end | [
"def",
"find_series",
"(",
"query_params",
"=",
"{",
"}",
")",
"set_default_presentation_context",
"(",
"\"1.2.840.10008.5.1.4.1.2.2.1\"",
")",
"default_query_params",
"=",
"{",
"\"0008,0052\"",
"=>",
"\"SERIES\"",
",",
"\"0008,0060\"",
"=>",
"\"\"",
",",
"\"0020,000E\"",
"=>",
"\"\"",
",",
"\"0020,0011\"",
"=>",
"\"\"",
"}",
"query_params",
".",
"keys",
".",
"each",
"do",
"|",
"tag",
"|",
"raise",
"ArgumentError",
",",
"\"The supplied tag (#{tag}) is not valid. It must be a string of the form 'GGGG,EEEE'.\"",
"unless",
"tag",
".",
"is_a?",
"(",
"String",
")",
"&&",
"tag",
".",
"tag?",
"end",
"set_data_elements",
"(",
"default_query_params",
".",
"merge",
"(",
"query_params",
")",
")",
"perform_find",
"return",
"@data_results",
"end"
]
| Queries a service class provider for series that match the specified criteria.
=== Instance level attributes for this query:
* '0008,0060' (Modality)
* '0020,000E' (Series Instance UID)
* '0020,0011' (Series Number)
In addition to the above listed attributes, a number of "optional" attributes
may be specified. For a general list of optional object instance level attributes,
please refer to the DICOM standard, PS3.4 C.6.1.1.4, Table C.6-3.
@note Caution: Calling this method without parameters will instruct your PACS
to return info on ALL series in the database!
@param [Hash] query_params the query parameters to use
@option query_params [String] 'GGGG,EEEE' a tag and value pair to be used in the query
@example Find all series belonging to the given study
node.find_series('0020,000D' => '1.2.840.1145.342') | [
"Queries",
"a",
"service",
"class",
"provider",
"for",
"series",
"that",
"match",
"the",
"specified",
"criteria",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/d_client.rb#L177-L196 | train |
dicom/ruby-dicom | lib/dicom/d_client.rb | DICOM.DClient.move_image | def move_image(destination, options={})
# Study Root Query/Retrieve Information Model - MOVE:
set_default_presentation_context("1.2.840.10008.5.1.4.1.2.2.2")
# Transfer the current options to the data_elements hash:
set_command_fragment_move(destination)
# Prepare data elements for this operation:
set_data_fragment_move_image
set_data_options(options)
perform_move
end | ruby | def move_image(destination, options={})
# Study Root Query/Retrieve Information Model - MOVE:
set_default_presentation_context("1.2.840.10008.5.1.4.1.2.2.2")
# Transfer the current options to the data_elements hash:
set_command_fragment_move(destination)
# Prepare data elements for this operation:
set_data_fragment_move_image
set_data_options(options)
perform_move
end | [
"def",
"move_image",
"(",
"destination",
",",
"options",
"=",
"{",
"}",
")",
"set_default_presentation_context",
"(",
"\"1.2.840.10008.5.1.4.1.2.2.2\"",
")",
"set_command_fragment_move",
"(",
"destination",
")",
"set_data_fragment_move_image",
"set_data_options",
"(",
"options",
")",
"perform_move",
"end"
]
| Moves a single image to a DICOM server.
This DICOM node must be a third party (i.e. not the client instance you
are requesting the move with!).
=== Instance level attributes for this procedure:
* '0008,0018' (SOP Instance UID)
* '0008,0052' (Query/Retrieve Level)
* '0020,000D' (Study Instance UID)
* '0020,000E' (Series Instance UID)
@param [String] destination the AE title of the DICOM server which will receive the file
@param [Hash] options the options to use for moving the DICOM object
@option options [String] 'GGGG,EEEE' a tag and value pair to be used for the procedure
@example Move an image from e.q. a PACS to another SCP on the network
node.move_image('SOME_SERVER', '0008,0018' => sop_uid, '0020,000D' => study_uid, '0020,000E' => series_uid) | [
"Moves",
"a",
"single",
"image",
"to",
"a",
"DICOM",
"server",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/d_client.rb#L296-L305 | train |
dicom/ruby-dicom | lib/dicom/d_client.rb | DICOM.DClient.move_study | def move_study(destination, options={})
# Study Root Query/Retrieve Information Model - MOVE:
set_default_presentation_context("1.2.840.10008.5.1.4.1.2.2.2")
# Transfer the current options to the data_elements hash:
set_command_fragment_move(destination)
# Prepare data elements for this operation:
set_data_fragment_move_study
set_data_options(options)
perform_move
end | ruby | def move_study(destination, options={})
# Study Root Query/Retrieve Information Model - MOVE:
set_default_presentation_context("1.2.840.10008.5.1.4.1.2.2.2")
# Transfer the current options to the data_elements hash:
set_command_fragment_move(destination)
# Prepare data elements for this operation:
set_data_fragment_move_study
set_data_options(options)
perform_move
end | [
"def",
"move_study",
"(",
"destination",
",",
"options",
"=",
"{",
"}",
")",
"set_default_presentation_context",
"(",
"\"1.2.840.10008.5.1.4.1.2.2.2\"",
")",
"set_command_fragment_move",
"(",
"destination",
")",
"set_data_fragment_move_study",
"set_data_options",
"(",
"options",
")",
"perform_move",
"end"
]
| Move an entire study to a DICOM server.
This DICOM node must be a third party (i.e. not the client instance you
are requesting the move with!).
=== Instance level attributes for this procedure:
* '0008,0052' (Query/Retrieve Level)
* '0010,0020' (Patient ID)
* '0020,000D' (Study Instance UID)
@param [String] destination the AE title of the DICOM server which will receive the files
@param [Hash] options the options to use for moving the DICOM objects
@option options [String] 'GGGG,EEEE' a tag and value pair to be used for the procedure
@example Move an entire study from e.q. a PACS to another SCP on the network
node.move_study('SOME_SERVER', '0010,0020' => pat_id, '0020,000D' => study_uid) | [
"Move",
"an",
"entire",
"study",
"to",
"a",
"DICOM",
"server",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/d_client.rb#L325-L334 | train |
dicom/ruby-dicom | lib/dicom/d_client.rb | DICOM.DClient.available_transfer_syntaxes | def available_transfer_syntaxes(transfer_syntax)
case transfer_syntax
when IMPLICIT_LITTLE_ENDIAN
return [IMPLICIT_LITTLE_ENDIAN, EXPLICIT_LITTLE_ENDIAN]
when EXPLICIT_LITTLE_ENDIAN
return [EXPLICIT_LITTLE_ENDIAN, IMPLICIT_LITTLE_ENDIAN]
when EXPLICIT_BIG_ENDIAN
return [EXPLICIT_BIG_ENDIAN, IMPLICIT_LITTLE_ENDIAN]
else # Compression:
return [transfer_syntax]
end
end | ruby | def available_transfer_syntaxes(transfer_syntax)
case transfer_syntax
when IMPLICIT_LITTLE_ENDIAN
return [IMPLICIT_LITTLE_ENDIAN, EXPLICIT_LITTLE_ENDIAN]
when EXPLICIT_LITTLE_ENDIAN
return [EXPLICIT_LITTLE_ENDIAN, IMPLICIT_LITTLE_ENDIAN]
when EXPLICIT_BIG_ENDIAN
return [EXPLICIT_BIG_ENDIAN, IMPLICIT_LITTLE_ENDIAN]
else # Compression:
return [transfer_syntax]
end
end | [
"def",
"available_transfer_syntaxes",
"(",
"transfer_syntax",
")",
"case",
"transfer_syntax",
"when",
"IMPLICIT_LITTLE_ENDIAN",
"return",
"[",
"IMPLICIT_LITTLE_ENDIAN",
",",
"EXPLICIT_LITTLE_ENDIAN",
"]",
"when",
"EXPLICIT_LITTLE_ENDIAN",
"return",
"[",
"EXPLICIT_LITTLE_ENDIAN",
",",
"IMPLICIT_LITTLE_ENDIAN",
"]",
"when",
"EXPLICIT_BIG_ENDIAN",
"return",
"[",
"EXPLICIT_BIG_ENDIAN",
",",
"IMPLICIT_LITTLE_ENDIAN",
"]",
"else",
"return",
"[",
"transfer_syntax",
"]",
"end",
"end"
]
| Returns an array of supported transfer syntaxes for the specified transfer syntax.
For compressed transfer syntaxes, we currently do not support reencoding these to other syntaxes. | [
"Returns",
"an",
"array",
"of",
"supported",
"transfer",
"syntaxes",
"for",
"the",
"specified",
"transfer",
"syntax",
".",
"For",
"compressed",
"transfer",
"syntaxes",
"we",
"currently",
"do",
"not",
"support",
"reencoding",
"these",
"to",
"other",
"syntaxes",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/d_client.rb#L395-L406 | train |
dicom/ruby-dicom | lib/dicom/d_client.rb | DICOM.DClient.establish_association | def establish_association
# Reset some variables:
@association = false
@request_approved = false
# Initiate the association:
@link.build_association_request(@presentation_contexts, @user_information)
@link.start_session(@host_ip, @port)
@link.transmit
info = @link.receive_multiple_transmissions.first
# Interpret the results:
if info && info[:valid]
if info[:pdu] == PDU_ASSOCIATION_ACCEPT
# Values of importance are extracted and put into instance variables:
@association = true
@max_pdu_length = info[:max_pdu_length]
logger.info("Association successfully negotiated with host #{@host_ae} (#{@host_ip}).")
# Check if all our presentation contexts was accepted by the host:
process_presentation_context_response(info[:pc])
else
logger.error("Association was denied from host #{@host_ae} (#{@host_ip})!")
end
end
end | ruby | def establish_association
# Reset some variables:
@association = false
@request_approved = false
# Initiate the association:
@link.build_association_request(@presentation_contexts, @user_information)
@link.start_session(@host_ip, @port)
@link.transmit
info = @link.receive_multiple_transmissions.first
# Interpret the results:
if info && info[:valid]
if info[:pdu] == PDU_ASSOCIATION_ACCEPT
# Values of importance are extracted and put into instance variables:
@association = true
@max_pdu_length = info[:max_pdu_length]
logger.info("Association successfully negotiated with host #{@host_ae} (#{@host_ip}).")
# Check if all our presentation contexts was accepted by the host:
process_presentation_context_response(info[:pc])
else
logger.error("Association was denied from host #{@host_ae} (#{@host_ip})!")
end
end
end | [
"def",
"establish_association",
"@association",
"=",
"false",
"@request_approved",
"=",
"false",
"@link",
".",
"build_association_request",
"(",
"@presentation_contexts",
",",
"@user_information",
")",
"@link",
".",
"start_session",
"(",
"@host_ip",
",",
"@port",
")",
"@link",
".",
"transmit",
"info",
"=",
"@link",
".",
"receive_multiple_transmissions",
".",
"first",
"if",
"info",
"&&",
"info",
"[",
":valid",
"]",
"if",
"info",
"[",
":pdu",
"]",
"==",
"PDU_ASSOCIATION_ACCEPT",
"@association",
"=",
"true",
"@max_pdu_length",
"=",
"info",
"[",
":max_pdu_length",
"]",
"logger",
".",
"info",
"(",
"\"Association successfully negotiated with host #{@host_ae} (#{@host_ip}).\"",
")",
"process_presentation_context_response",
"(",
"info",
"[",
":pc",
"]",
")",
"else",
"logger",
".",
"error",
"(",
"\"Association was denied from host #{@host_ae} (#{@host_ip})!\"",
")",
"end",
"end",
"end"
]
| Opens a TCP session with the server, and handles the association request as well as the response. | [
"Opens",
"a",
"TCP",
"session",
"with",
"the",
"server",
"and",
"handles",
"the",
"association",
"request",
"as",
"well",
"as",
"the",
"response",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/d_client.rb#L410-L432 | train |
dicom/ruby-dicom | lib/dicom/d_client.rb | DICOM.DClient.establish_release | def establish_release
@release = false
if @abort
@link.stop_session
logger.info("Association has been closed. (#{@host_ae}, #{@host_ip})")
else
unless @link.session.closed?
@link.build_release_request
@link.transmit
info = @link.receive_single_transmission.first
@link.stop_session
if info[:pdu] == PDU_RELEASE_RESPONSE
logger.info("Association released properly from host #{@host_ae}.")
else
logger.error("Association released from host #{@host_ae}, but a release response was not registered.")
end
else
logger.error("Connection was closed by the host (for some unknown reason) before the association could be released properly.")
end
end
@abort = false
end | ruby | def establish_release
@release = false
if @abort
@link.stop_session
logger.info("Association has been closed. (#{@host_ae}, #{@host_ip})")
else
unless @link.session.closed?
@link.build_release_request
@link.transmit
info = @link.receive_single_transmission.first
@link.stop_session
if info[:pdu] == PDU_RELEASE_RESPONSE
logger.info("Association released properly from host #{@host_ae}.")
else
logger.error("Association released from host #{@host_ae}, but a release response was not registered.")
end
else
logger.error("Connection was closed by the host (for some unknown reason) before the association could be released properly.")
end
end
@abort = false
end | [
"def",
"establish_release",
"@release",
"=",
"false",
"if",
"@abort",
"@link",
".",
"stop_session",
"logger",
".",
"info",
"(",
"\"Association has been closed. (#{@host_ae}, #{@host_ip})\"",
")",
"else",
"unless",
"@link",
".",
"session",
".",
"closed?",
"@link",
".",
"build_release_request",
"@link",
".",
"transmit",
"info",
"=",
"@link",
".",
"receive_single_transmission",
".",
"first",
"@link",
".",
"stop_session",
"if",
"info",
"[",
":pdu",
"]",
"==",
"PDU_RELEASE_RESPONSE",
"logger",
".",
"info",
"(",
"\"Association released properly from host #{@host_ae}.\"",
")",
"else",
"logger",
".",
"error",
"(",
"\"Association released from host #{@host_ae}, but a release response was not registered.\"",
")",
"end",
"else",
"logger",
".",
"error",
"(",
"\"Connection was closed by the host (for some unknown reason) before the association could be released properly.\"",
")",
"end",
"end",
"@abort",
"=",
"false",
"end"
]
| Handles the release request along with the response, as well as closing the TCP connection. | [
"Handles",
"the",
"release",
"request",
"along",
"with",
"the",
"response",
"as",
"well",
"as",
"closing",
"the",
"TCP",
"connection",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/d_client.rb#L436-L457 | train |
dicom/ruby-dicom | lib/dicom/d_client.rb | DICOM.DClient.load_files | def load_files(files_or_objects)
files_or_objects = [files_or_objects] unless files_or_objects.is_a?(Array)
status = true
message = ""
objects = Array.new
abstracts = Array.new
id = 1
@presentation_contexts = Hash.new
files_or_objects.each do |file_or_object|
if file_or_object.is_a?(String)
# Temporarily increase the log threshold to suppress messages from the DObject class:
client_level = logger.level
logger.level = Logger::FATAL
dcm = DObject.read(file_or_object)
# Reset the logg threshold:
logger.level = client_level
if dcm.read_success
# Load the DICOM object:
objects << dcm
else
status = false
message = "Failed to read a DObject from this file: #{file_or_object}"
end
elsif file_or_object.is_a?(DObject)
# Load the DICOM object and its abstract syntax:
abstracts << file_or_object.value("0008,0016")
objects << file_or_object
else
status = false
message = "Array contains invalid object: #{file_or_object.class}."
end
end
# Extract available transfer syntaxes for the various sop classes found amongst these objects
syntaxes = Hash.new
objects.each do |dcm|
sop_class = dcm.value("0008,0016")
if sop_class
transfer_syntaxes = available_transfer_syntaxes(dcm.transfer_syntax)
if syntaxes[sop_class]
syntaxes[sop_class] << transfer_syntaxes
else
syntaxes[sop_class] = transfer_syntaxes
end
else
status = false
message = "Missing SOP Class UID. Unable to transmit DICOM object"
end
# Extract the unique variations of SOP Class and syntaxes and construct the presentation context hash:
syntaxes.each_pair do |sop_class, ts|
selected_transfer_syntaxes = ts.flatten.uniq
@presentation_contexts[sop_class] = Hash.new
selected_transfer_syntaxes.each do |syntax|
@presentation_contexts[sop_class][id] = {:transfer_syntaxes => [syntax]}
id += 2
end
end
end
return objects, status, message
end | ruby | def load_files(files_or_objects)
files_or_objects = [files_or_objects] unless files_or_objects.is_a?(Array)
status = true
message = ""
objects = Array.new
abstracts = Array.new
id = 1
@presentation_contexts = Hash.new
files_or_objects.each do |file_or_object|
if file_or_object.is_a?(String)
# Temporarily increase the log threshold to suppress messages from the DObject class:
client_level = logger.level
logger.level = Logger::FATAL
dcm = DObject.read(file_or_object)
# Reset the logg threshold:
logger.level = client_level
if dcm.read_success
# Load the DICOM object:
objects << dcm
else
status = false
message = "Failed to read a DObject from this file: #{file_or_object}"
end
elsif file_or_object.is_a?(DObject)
# Load the DICOM object and its abstract syntax:
abstracts << file_or_object.value("0008,0016")
objects << file_or_object
else
status = false
message = "Array contains invalid object: #{file_or_object.class}."
end
end
# Extract available transfer syntaxes for the various sop classes found amongst these objects
syntaxes = Hash.new
objects.each do |dcm|
sop_class = dcm.value("0008,0016")
if sop_class
transfer_syntaxes = available_transfer_syntaxes(dcm.transfer_syntax)
if syntaxes[sop_class]
syntaxes[sop_class] << transfer_syntaxes
else
syntaxes[sop_class] = transfer_syntaxes
end
else
status = false
message = "Missing SOP Class UID. Unable to transmit DICOM object"
end
# Extract the unique variations of SOP Class and syntaxes and construct the presentation context hash:
syntaxes.each_pair do |sop_class, ts|
selected_transfer_syntaxes = ts.flatten.uniq
@presentation_contexts[sop_class] = Hash.new
selected_transfer_syntaxes.each do |syntax|
@presentation_contexts[sop_class][id] = {:transfer_syntaxes => [syntax]}
id += 2
end
end
end
return objects, status, message
end | [
"def",
"load_files",
"(",
"files_or_objects",
")",
"files_or_objects",
"=",
"[",
"files_or_objects",
"]",
"unless",
"files_or_objects",
".",
"is_a?",
"(",
"Array",
")",
"status",
"=",
"true",
"message",
"=",
"\"\"",
"objects",
"=",
"Array",
".",
"new",
"abstracts",
"=",
"Array",
".",
"new",
"id",
"=",
"1",
"@presentation_contexts",
"=",
"Hash",
".",
"new",
"files_or_objects",
".",
"each",
"do",
"|",
"file_or_object",
"|",
"if",
"file_or_object",
".",
"is_a?",
"(",
"String",
")",
"client_level",
"=",
"logger",
".",
"level",
"logger",
".",
"level",
"=",
"Logger",
"::",
"FATAL",
"dcm",
"=",
"DObject",
".",
"read",
"(",
"file_or_object",
")",
"logger",
".",
"level",
"=",
"client_level",
"if",
"dcm",
".",
"read_success",
"objects",
"<<",
"dcm",
"else",
"status",
"=",
"false",
"message",
"=",
"\"Failed to read a DObject from this file: #{file_or_object}\"",
"end",
"elsif",
"file_or_object",
".",
"is_a?",
"(",
"DObject",
")",
"abstracts",
"<<",
"file_or_object",
".",
"value",
"(",
"\"0008,0016\"",
")",
"objects",
"<<",
"file_or_object",
"else",
"status",
"=",
"false",
"message",
"=",
"\"Array contains invalid object: #{file_or_object.class}.\"",
"end",
"end",
"syntaxes",
"=",
"Hash",
".",
"new",
"objects",
".",
"each",
"do",
"|",
"dcm",
"|",
"sop_class",
"=",
"dcm",
".",
"value",
"(",
"\"0008,0016\"",
")",
"if",
"sop_class",
"transfer_syntaxes",
"=",
"available_transfer_syntaxes",
"(",
"dcm",
".",
"transfer_syntax",
")",
"if",
"syntaxes",
"[",
"sop_class",
"]",
"syntaxes",
"[",
"sop_class",
"]",
"<<",
"transfer_syntaxes",
"else",
"syntaxes",
"[",
"sop_class",
"]",
"=",
"transfer_syntaxes",
"end",
"else",
"status",
"=",
"false",
"message",
"=",
"\"Missing SOP Class UID. Unable to transmit DICOM object\"",
"end",
"syntaxes",
".",
"each_pair",
"do",
"|",
"sop_class",
",",
"ts",
"|",
"selected_transfer_syntaxes",
"=",
"ts",
".",
"flatten",
".",
"uniq",
"@presentation_contexts",
"[",
"sop_class",
"]",
"=",
"Hash",
".",
"new",
"selected_transfer_syntaxes",
".",
"each",
"do",
"|",
"syntax",
"|",
"@presentation_contexts",
"[",
"sop_class",
"]",
"[",
"id",
"]",
"=",
"{",
":transfer_syntaxes",
"=>",
"[",
"syntax",
"]",
"}",
"id",
"+=",
"2",
"end",
"end",
"end",
"return",
"objects",
",",
"status",
",",
"message",
"end"
]
| Loads one or more DICOM files.
Returns an array of DObject instances, an array of unique abstract syntaxes found among the files, a status boolean and a message string.
=== Parameters
* <tt>files_or_objects</tt> -- A single file path or an array of paths, or a DObject or an array of DObject instances. | [
"Loads",
"one",
"or",
"more",
"DICOM",
"files",
".",
"Returns",
"an",
"array",
"of",
"DObject",
"instances",
"an",
"array",
"of",
"unique",
"abstract",
"syntaxes",
"found",
"among",
"the",
"files",
"a",
"status",
"boolean",
"and",
"a",
"message",
"string",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/d_client.rb#L474-L532 | train |
dicom/ruby-dicom | lib/dicom/d_client.rb | DICOM.DClient.perform_echo | def perform_echo
# Open a DICOM link:
establish_association
if association_established?
if request_approved?
# Continue with our echo, since the request was accepted.
# Set the query command elements array:
set_command_fragment_echo
@link.build_command_fragment(PDU_DATA, presentation_context_id, COMMAND_LAST_FRAGMENT, @command_elements)
@link.transmit
# Listen for incoming responses and interpret them individually, until we have received the last command fragment.
segments = @link.receive_multiple_transmissions
process_returned_data(segments)
# Print stuff to screen?
end
# Close the DICOM link:
establish_release
end
end | ruby | def perform_echo
# Open a DICOM link:
establish_association
if association_established?
if request_approved?
# Continue with our echo, since the request was accepted.
# Set the query command elements array:
set_command_fragment_echo
@link.build_command_fragment(PDU_DATA, presentation_context_id, COMMAND_LAST_FRAGMENT, @command_elements)
@link.transmit
# Listen for incoming responses and interpret them individually, until we have received the last command fragment.
segments = @link.receive_multiple_transmissions
process_returned_data(segments)
# Print stuff to screen?
end
# Close the DICOM link:
establish_release
end
end | [
"def",
"perform_echo",
"establish_association",
"if",
"association_established?",
"if",
"request_approved?",
"set_command_fragment_echo",
"@link",
".",
"build_command_fragment",
"(",
"PDU_DATA",
",",
"presentation_context_id",
",",
"COMMAND_LAST_FRAGMENT",
",",
"@command_elements",
")",
"@link",
".",
"transmit",
"segments",
"=",
"@link",
".",
"receive_multiple_transmissions",
"process_returned_data",
"(",
"segments",
")",
"end",
"establish_release",
"end",
"end"
]
| Handles the communication involved in a DICOM C-ECHO.
Build the necessary strings and send the command and data element that makes up the echo request.
Listens for and interpretes the incoming echo response. | [
"Handles",
"the",
"communication",
"involved",
"in",
"a",
"DICOM",
"C",
"-",
"ECHO",
".",
"Build",
"the",
"necessary",
"strings",
"and",
"send",
"the",
"command",
"and",
"data",
"element",
"that",
"makes",
"up",
"the",
"echo",
"request",
".",
"Listens",
"for",
"and",
"interpretes",
"the",
"incoming",
"echo",
"response",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/d_client.rb#L538-L556 | train |
dicom/ruby-dicom | lib/dicom/d_client.rb | DICOM.DClient.perform_get | def perform_get(path)
# Open a DICOM link:
establish_association
if association_established?
if request_approved?
# Continue with our operation, since the request was accepted.
@link.build_command_fragment(PDU_DATA, presentation_context_id, COMMAND_LAST_FRAGMENT, @command_elements)
@link.transmit
@link.build_data_fragment(@data_elements, presentation_context_id)
@link.transmit
# Listen for incoming file data:
success = @link.handle_incoming_data(path)
if success
# Send confirmation response:
@link.handle_response
end
end
# Close the DICOM link:
establish_release
end
end | ruby | def perform_get(path)
# Open a DICOM link:
establish_association
if association_established?
if request_approved?
# Continue with our operation, since the request was accepted.
@link.build_command_fragment(PDU_DATA, presentation_context_id, COMMAND_LAST_FRAGMENT, @command_elements)
@link.transmit
@link.build_data_fragment(@data_elements, presentation_context_id)
@link.transmit
# Listen for incoming file data:
success = @link.handle_incoming_data(path)
if success
# Send confirmation response:
@link.handle_response
end
end
# Close the DICOM link:
establish_release
end
end | [
"def",
"perform_get",
"(",
"path",
")",
"establish_association",
"if",
"association_established?",
"if",
"request_approved?",
"@link",
".",
"build_command_fragment",
"(",
"PDU_DATA",
",",
"presentation_context_id",
",",
"COMMAND_LAST_FRAGMENT",
",",
"@command_elements",
")",
"@link",
".",
"transmit",
"@link",
".",
"build_data_fragment",
"(",
"@data_elements",
",",
"presentation_context_id",
")",
"@link",
".",
"transmit",
"success",
"=",
"@link",
".",
"handle_incoming_data",
"(",
"path",
")",
"if",
"success",
"@link",
".",
"handle_response",
"end",
"end",
"establish_release",
"end",
"end"
]
| Handles the communication involved in a DICOM C-GET.
Builds and sends command & data fragment, then receives the incoming file data.
--
FIXME: This method has never actually been tested, since it is difficult to find a host that accepts a c-get-rq. | [
"Handles",
"the",
"communication",
"involved",
"in",
"a",
"DICOM",
"C",
"-",
"GET",
".",
"Builds",
"and",
"sends",
"command",
"&",
"data",
"fragment",
"then",
"receives",
"the",
"incoming",
"file",
"data",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/d_client.rb#L590-L610 | train |
dicom/ruby-dicom | lib/dicom/d_client.rb | DICOM.DClient.perform_send | def perform_send(objects)
objects.each_with_index do |dcm, index|
# Gather necessary information from the object (SOP Class & Instance UID):
sop_class = dcm.value("0008,0016")
sop_instance = dcm.value("0008,0018")
if sop_class and sop_instance
# Only send the image if its sop_class has been accepted by the receiver:
if @approved_syntaxes[sop_class]
# Set the command array to be used:
message_id = index + 1
set_command_fragment_store(sop_class, sop_instance, message_id)
# Find context id and transfer syntax:
presentation_context_id = @approved_syntaxes[sop_class][0]
selected_transfer_syntax = @approved_syntaxes[sop_class][1]
# Encode our DICOM object to a binary string which is split up in pieces, sufficiently small to fit within the specified maximum pdu length:
# Set the transfer syntax of the DICOM object equal to the one accepted by the SCP:
dcm.transfer_syntax = selected_transfer_syntax
# Remove the Meta group, since it doesn't belong in a DICOM file transfer:
dcm.delete_group(META_GROUP)
max_header_length = 14
data_packages = dcm.encode_segments(@max_pdu_length - max_header_length, selected_transfer_syntax)
@link.build_command_fragment(PDU_DATA, presentation_context_id, COMMAND_LAST_FRAGMENT, @command_elements)
@link.transmit
# Transmit all but the last data strings:
last_data_package = data_packages.pop
data_packages.each do |data_package|
@link.build_storage_fragment(PDU_DATA, presentation_context_id, DATA_MORE_FRAGMENTS, data_package)
@link.transmit
end
# Transmit the last data string:
@link.build_storage_fragment(PDU_DATA, presentation_context_id, DATA_LAST_FRAGMENT, last_data_package)
@link.transmit
# Receive confirmation response:
segments = @link.receive_single_transmission
process_returned_data(segments)
end
else
logger.error("Unable to extract SOP Class UID and/or SOP Instance UID for this DICOM object. File will not be sent to its destination.")
end
end
end | ruby | def perform_send(objects)
objects.each_with_index do |dcm, index|
# Gather necessary information from the object (SOP Class & Instance UID):
sop_class = dcm.value("0008,0016")
sop_instance = dcm.value("0008,0018")
if sop_class and sop_instance
# Only send the image if its sop_class has been accepted by the receiver:
if @approved_syntaxes[sop_class]
# Set the command array to be used:
message_id = index + 1
set_command_fragment_store(sop_class, sop_instance, message_id)
# Find context id and transfer syntax:
presentation_context_id = @approved_syntaxes[sop_class][0]
selected_transfer_syntax = @approved_syntaxes[sop_class][1]
# Encode our DICOM object to a binary string which is split up in pieces, sufficiently small to fit within the specified maximum pdu length:
# Set the transfer syntax of the DICOM object equal to the one accepted by the SCP:
dcm.transfer_syntax = selected_transfer_syntax
# Remove the Meta group, since it doesn't belong in a DICOM file transfer:
dcm.delete_group(META_GROUP)
max_header_length = 14
data_packages = dcm.encode_segments(@max_pdu_length - max_header_length, selected_transfer_syntax)
@link.build_command_fragment(PDU_DATA, presentation_context_id, COMMAND_LAST_FRAGMENT, @command_elements)
@link.transmit
# Transmit all but the last data strings:
last_data_package = data_packages.pop
data_packages.each do |data_package|
@link.build_storage_fragment(PDU_DATA, presentation_context_id, DATA_MORE_FRAGMENTS, data_package)
@link.transmit
end
# Transmit the last data string:
@link.build_storage_fragment(PDU_DATA, presentation_context_id, DATA_LAST_FRAGMENT, last_data_package)
@link.transmit
# Receive confirmation response:
segments = @link.receive_single_transmission
process_returned_data(segments)
end
else
logger.error("Unable to extract SOP Class UID and/or SOP Instance UID for this DICOM object. File will not be sent to its destination.")
end
end
end | [
"def",
"perform_send",
"(",
"objects",
")",
"objects",
".",
"each_with_index",
"do",
"|",
"dcm",
",",
"index",
"|",
"sop_class",
"=",
"dcm",
".",
"value",
"(",
"\"0008,0016\"",
")",
"sop_instance",
"=",
"dcm",
".",
"value",
"(",
"\"0008,0018\"",
")",
"if",
"sop_class",
"and",
"sop_instance",
"if",
"@approved_syntaxes",
"[",
"sop_class",
"]",
"message_id",
"=",
"index",
"+",
"1",
"set_command_fragment_store",
"(",
"sop_class",
",",
"sop_instance",
",",
"message_id",
")",
"presentation_context_id",
"=",
"@approved_syntaxes",
"[",
"sop_class",
"]",
"[",
"0",
"]",
"selected_transfer_syntax",
"=",
"@approved_syntaxes",
"[",
"sop_class",
"]",
"[",
"1",
"]",
"dcm",
".",
"transfer_syntax",
"=",
"selected_transfer_syntax",
"dcm",
".",
"delete_group",
"(",
"META_GROUP",
")",
"max_header_length",
"=",
"14",
"data_packages",
"=",
"dcm",
".",
"encode_segments",
"(",
"@max_pdu_length",
"-",
"max_header_length",
",",
"selected_transfer_syntax",
")",
"@link",
".",
"build_command_fragment",
"(",
"PDU_DATA",
",",
"presentation_context_id",
",",
"COMMAND_LAST_FRAGMENT",
",",
"@command_elements",
")",
"@link",
".",
"transmit",
"last_data_package",
"=",
"data_packages",
".",
"pop",
"data_packages",
".",
"each",
"do",
"|",
"data_package",
"|",
"@link",
".",
"build_storage_fragment",
"(",
"PDU_DATA",
",",
"presentation_context_id",
",",
"DATA_MORE_FRAGMENTS",
",",
"data_package",
")",
"@link",
".",
"transmit",
"end",
"@link",
".",
"build_storage_fragment",
"(",
"PDU_DATA",
",",
"presentation_context_id",
",",
"DATA_LAST_FRAGMENT",
",",
"last_data_package",
")",
"@link",
".",
"transmit",
"segments",
"=",
"@link",
".",
"receive_single_transmission",
"process_returned_data",
"(",
"segments",
")",
"end",
"else",
"logger",
".",
"error",
"(",
"\"Unable to extract SOP Class UID and/or SOP Instance UID for this DICOM object. File will not be sent to its destination.\"",
")",
"end",
"end",
"end"
]
| Handles the communication involved in DICOM C-STORE.
For each file, builds and sends command fragment, then builds and sends the data fragments that
conveys the information from the selected DICOM file. | [
"Handles",
"the",
"communication",
"involved",
"in",
"DICOM",
"C",
"-",
"STORE",
".",
"For",
"each",
"file",
"builds",
"and",
"sends",
"command",
"fragment",
"then",
"builds",
"and",
"sends",
"the",
"data",
"fragments",
"that",
"conveys",
"the",
"information",
"from",
"the",
"selected",
"DICOM",
"file",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/d_client.rb#L639-L679 | train |
dicom/ruby-dicom | lib/dicom/d_client.rb | DICOM.DClient.process_presentation_context_response | def process_presentation_context_response(presentation_contexts)
# Storing approved syntaxes in an Hash with the syntax as key and the value being an array with presentation context ID and the transfer syntax chosen by the SCP.
@approved_syntaxes = Hash.new
rejected = Hash.new
# Reset the presentation context instance variable:
@link.presentation_contexts = Hash.new
accepted_pc = 0
presentation_contexts.each do |pc|
# Determine what abstract syntax this particular presentation context's id corresponds to:
id = pc[:presentation_context_id]
raise "Error! Even presentation context ID received in the association response. This is not allowed according to the DICOM standard!" if id.even?
abstract_syntax = find_abstract_syntax(id)
if pc[:result] == 0
accepted_pc += 1
@approved_syntaxes[abstract_syntax] = [id, pc[:transfer_syntax]]
@link.presentation_contexts[id] = pc[:transfer_syntax]
else
rejected[abstract_syntax] = [id, pc[:transfer_syntax]]
end
end
if rejected.length == 0
@request_approved = true
if @approved_syntaxes.length == 1 and presentation_contexts.length == 1
logger.info("The presentation context was accepted by host #{@host_ae}.")
else
logger.info("All #{presentation_contexts.length} presentation contexts were accepted by host #{@host_ae} (#{@host_ip}).")
end
else
# We still consider the request 'approved' if at least one context were accepted:
@request_approved = true if @approved_syntaxes.length > 0
logger.error("One or more of your presentation contexts were denied by host #{@host_ae}!")
@approved_syntaxes.each_pair do |key, value|
sntx_k = (LIBRARY.uid(key) ? LIBRARY.uid(key).name : 'Unknown UID!')
sntx_v = (LIBRARY.uid(value[1]) ? LIBRARY.uid(value[1]).name : 'Unknown UID!')
logger.info("APPROVED: #{sntx_k} (#{sntx_v})")
end
rejected.each_pair do |key, value|
sntx_k = (LIBRARY.uid(key) ? LIBRARY.uid(key).name : 'Unknown UID!')
sntx_v = (LIBRARY.uid(value[1]) ? LIBRARY.uid(value[1]).name : 'Unknown UID!')
logger.error("REJECTED: #{sntx_k} (#{sntx_v})")
end
end
end | ruby | def process_presentation_context_response(presentation_contexts)
# Storing approved syntaxes in an Hash with the syntax as key and the value being an array with presentation context ID and the transfer syntax chosen by the SCP.
@approved_syntaxes = Hash.new
rejected = Hash.new
# Reset the presentation context instance variable:
@link.presentation_contexts = Hash.new
accepted_pc = 0
presentation_contexts.each do |pc|
# Determine what abstract syntax this particular presentation context's id corresponds to:
id = pc[:presentation_context_id]
raise "Error! Even presentation context ID received in the association response. This is not allowed according to the DICOM standard!" if id.even?
abstract_syntax = find_abstract_syntax(id)
if pc[:result] == 0
accepted_pc += 1
@approved_syntaxes[abstract_syntax] = [id, pc[:transfer_syntax]]
@link.presentation_contexts[id] = pc[:transfer_syntax]
else
rejected[abstract_syntax] = [id, pc[:transfer_syntax]]
end
end
if rejected.length == 0
@request_approved = true
if @approved_syntaxes.length == 1 and presentation_contexts.length == 1
logger.info("The presentation context was accepted by host #{@host_ae}.")
else
logger.info("All #{presentation_contexts.length} presentation contexts were accepted by host #{@host_ae} (#{@host_ip}).")
end
else
# We still consider the request 'approved' if at least one context were accepted:
@request_approved = true if @approved_syntaxes.length > 0
logger.error("One or more of your presentation contexts were denied by host #{@host_ae}!")
@approved_syntaxes.each_pair do |key, value|
sntx_k = (LIBRARY.uid(key) ? LIBRARY.uid(key).name : 'Unknown UID!')
sntx_v = (LIBRARY.uid(value[1]) ? LIBRARY.uid(value[1]).name : 'Unknown UID!')
logger.info("APPROVED: #{sntx_k} (#{sntx_v})")
end
rejected.each_pair do |key, value|
sntx_k = (LIBRARY.uid(key) ? LIBRARY.uid(key).name : 'Unknown UID!')
sntx_v = (LIBRARY.uid(value[1]) ? LIBRARY.uid(value[1]).name : 'Unknown UID!')
logger.error("REJECTED: #{sntx_k} (#{sntx_v})")
end
end
end | [
"def",
"process_presentation_context_response",
"(",
"presentation_contexts",
")",
"@approved_syntaxes",
"=",
"Hash",
".",
"new",
"rejected",
"=",
"Hash",
".",
"new",
"@link",
".",
"presentation_contexts",
"=",
"Hash",
".",
"new",
"accepted_pc",
"=",
"0",
"presentation_contexts",
".",
"each",
"do",
"|",
"pc",
"|",
"id",
"=",
"pc",
"[",
":presentation_context_id",
"]",
"raise",
"\"Error! Even presentation context ID received in the association response. This is not allowed according to the DICOM standard!\"",
"if",
"id",
".",
"even?",
"abstract_syntax",
"=",
"find_abstract_syntax",
"(",
"id",
")",
"if",
"pc",
"[",
":result",
"]",
"==",
"0",
"accepted_pc",
"+=",
"1",
"@approved_syntaxes",
"[",
"abstract_syntax",
"]",
"=",
"[",
"id",
",",
"pc",
"[",
":transfer_syntax",
"]",
"]",
"@link",
".",
"presentation_contexts",
"[",
"id",
"]",
"=",
"pc",
"[",
":transfer_syntax",
"]",
"else",
"rejected",
"[",
"abstract_syntax",
"]",
"=",
"[",
"id",
",",
"pc",
"[",
":transfer_syntax",
"]",
"]",
"end",
"end",
"if",
"rejected",
".",
"length",
"==",
"0",
"@request_approved",
"=",
"true",
"if",
"@approved_syntaxes",
".",
"length",
"==",
"1",
"and",
"presentation_contexts",
".",
"length",
"==",
"1",
"logger",
".",
"info",
"(",
"\"The presentation context was accepted by host #{@host_ae}.\"",
")",
"else",
"logger",
".",
"info",
"(",
"\"All #{presentation_contexts.length} presentation contexts were accepted by host #{@host_ae} (#{@host_ip}).\"",
")",
"end",
"else",
"@request_approved",
"=",
"true",
"if",
"@approved_syntaxes",
".",
"length",
">",
"0",
"logger",
".",
"error",
"(",
"\"One or more of your presentation contexts were denied by host #{@host_ae}!\"",
")",
"@approved_syntaxes",
".",
"each_pair",
"do",
"|",
"key",
",",
"value",
"|",
"sntx_k",
"=",
"(",
"LIBRARY",
".",
"uid",
"(",
"key",
")",
"?",
"LIBRARY",
".",
"uid",
"(",
"key",
")",
".",
"name",
":",
"'Unknown UID!'",
")",
"sntx_v",
"=",
"(",
"LIBRARY",
".",
"uid",
"(",
"value",
"[",
"1",
"]",
")",
"?",
"LIBRARY",
".",
"uid",
"(",
"value",
"[",
"1",
"]",
")",
".",
"name",
":",
"'Unknown UID!'",
")",
"logger",
".",
"info",
"(",
"\"APPROVED: #{sntx_k} (#{sntx_v})\"",
")",
"end",
"rejected",
".",
"each_pair",
"do",
"|",
"key",
",",
"value",
"|",
"sntx_k",
"=",
"(",
"LIBRARY",
".",
"uid",
"(",
"key",
")",
"?",
"LIBRARY",
".",
"uid",
"(",
"key",
")",
".",
"name",
":",
"'Unknown UID!'",
")",
"sntx_v",
"=",
"(",
"LIBRARY",
".",
"uid",
"(",
"value",
"[",
"1",
"]",
")",
"?",
"LIBRARY",
".",
"uid",
"(",
"value",
"[",
"1",
"]",
")",
".",
"name",
":",
"'Unknown UID!'",
")",
"logger",
".",
"error",
"(",
"\"REJECTED: #{sntx_k} (#{sntx_v})\"",
")",
"end",
"end",
"end"
]
| Processes the presentation contexts that are received in the association response
to extract the transfer syntaxes which have been accepted for the various abstract syntaxes.
=== Parameters
* <tt>presentation_contexts</tt> -- An array where each index contains a presentation context hash. | [
"Processes",
"the",
"presentation",
"contexts",
"that",
"are",
"received",
"in",
"the",
"association",
"response",
"to",
"extract",
"the",
"transfer",
"syntaxes",
"which",
"have",
"been",
"accepted",
"for",
"the",
"various",
"abstract",
"syntaxes",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/d_client.rb#L688-L730 | train |
dicom/ruby-dicom | lib/dicom/d_client.rb | DICOM.DClient.process_returned_data | def process_returned_data(segments)
# Reset command results arrays:
@command_results = Array.new
@data_results = Array.new
# Try to extract data:
segments.each do |info|
if info[:valid]
# Determine if it is command or data:
if info[:presentation_context_flag] == COMMAND_LAST_FRAGMENT
@command_results << info[:results]
elsif info[:presentation_context_flag] == DATA_LAST_FRAGMENT
@data_results << info[:results]
end
end
end
end | ruby | def process_returned_data(segments)
# Reset command results arrays:
@command_results = Array.new
@data_results = Array.new
# Try to extract data:
segments.each do |info|
if info[:valid]
# Determine if it is command or data:
if info[:presentation_context_flag] == COMMAND_LAST_FRAGMENT
@command_results << info[:results]
elsif info[:presentation_context_flag] == DATA_LAST_FRAGMENT
@data_results << info[:results]
end
end
end
end | [
"def",
"process_returned_data",
"(",
"segments",
")",
"@command_results",
"=",
"Array",
".",
"new",
"@data_results",
"=",
"Array",
".",
"new",
"segments",
".",
"each",
"do",
"|",
"info",
"|",
"if",
"info",
"[",
":valid",
"]",
"if",
"info",
"[",
":presentation_context_flag",
"]",
"==",
"COMMAND_LAST_FRAGMENT",
"@command_results",
"<<",
"info",
"[",
":results",
"]",
"elsif",
"info",
"[",
":presentation_context_flag",
"]",
"==",
"DATA_LAST_FRAGMENT",
"@data_results",
"<<",
"info",
"[",
":results",
"]",
"end",
"end",
"end",
"end"
]
| Processes the array of information hashes that was returned from the interaction with the SCP
and transfers it to the instance variables where command and data results are stored. | [
"Processes",
"the",
"array",
"of",
"information",
"hashes",
"that",
"was",
"returned",
"from",
"the",
"interaction",
"with",
"the",
"SCP",
"and",
"transfers",
"it",
"to",
"the",
"instance",
"variables",
"where",
"command",
"and",
"data",
"results",
"are",
"stored",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/d_client.rb#L735-L750 | train |
dicom/ruby-dicom | lib/dicom/d_client.rb | DICOM.DClient.set_default_presentation_context | def set_default_presentation_context(abstract_syntax)
raise ArgumentError, "Expected String, got #{abstract_syntax.class}" unless abstract_syntax.is_a?(String)
id = 1
transfer_syntaxes = [IMPLICIT_LITTLE_ENDIAN, EXPLICIT_LITTLE_ENDIAN, EXPLICIT_BIG_ENDIAN]
item = {:transfer_syntaxes => transfer_syntaxes}
pc = {id => item}
@presentation_contexts = {abstract_syntax => pc}
end | ruby | def set_default_presentation_context(abstract_syntax)
raise ArgumentError, "Expected String, got #{abstract_syntax.class}" unless abstract_syntax.is_a?(String)
id = 1
transfer_syntaxes = [IMPLICIT_LITTLE_ENDIAN, EXPLICIT_LITTLE_ENDIAN, EXPLICIT_BIG_ENDIAN]
item = {:transfer_syntaxes => transfer_syntaxes}
pc = {id => item}
@presentation_contexts = {abstract_syntax => pc}
end | [
"def",
"set_default_presentation_context",
"(",
"abstract_syntax",
")",
"raise",
"ArgumentError",
",",
"\"Expected String, got #{abstract_syntax.class}\"",
"unless",
"abstract_syntax",
".",
"is_a?",
"(",
"String",
")",
"id",
"=",
"1",
"transfer_syntaxes",
"=",
"[",
"IMPLICIT_LITTLE_ENDIAN",
",",
"EXPLICIT_LITTLE_ENDIAN",
",",
"EXPLICIT_BIG_ENDIAN",
"]",
"item",
"=",
"{",
":transfer_syntaxes",
"=>",
"transfer_syntaxes",
"}",
"pc",
"=",
"{",
"id",
"=>",
"item",
"}",
"@presentation_contexts",
"=",
"{",
"abstract_syntax",
"=>",
"pc",
"}",
"end"
]
| Creates the presentation context used for the non-file-transmission association requests.. | [
"Creates",
"the",
"presentation",
"context",
"used",
"for",
"the",
"non",
"-",
"file",
"-",
"transmission",
"association",
"requests",
".."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/d_client.rb#L867-L874 | train |
dicom/ruby-dicom | lib/dicom/d_client.rb | DICOM.DClient.set_data_elements | def set_data_elements(options)
@data_elements = []
options.keys.sort.each do |tag|
@data_elements << [ tag, options[tag] ] unless options[tag].nil?
end
end | ruby | def set_data_elements(options)
@data_elements = []
options.keys.sort.each do |tag|
@data_elements << [ tag, options[tag] ] unless options[tag].nil?
end
end | [
"def",
"set_data_elements",
"(",
"options",
")",
"@data_elements",
"=",
"[",
"]",
"options",
".",
"keys",
".",
"sort",
".",
"each",
"do",
"|",
"tag",
"|",
"@data_elements",
"<<",
"[",
"tag",
",",
"options",
"[",
"tag",
"]",
"]",
"unless",
"options",
"[",
"tag",
"]",
".",
"nil?",
"end",
"end"
]
| Sets the data_elements instance array with the given options. | [
"Sets",
"the",
"data_elements",
"instance",
"array",
"with",
"the",
"given",
"options",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/d_client.rb#L910-L915 | train |
calabash/calabash | lib/calabash/console_helpers.rb | Calabash.ConsoleHelpers.reload_git_files | def reload_git_files
files_to_reload =
(`git status`.lines.grep(/modified/).map{|l| l.split(" ").last.gsub('../', '')} +
`git ls-files --others --exclude-standard`.lines).map(&:chomp)
$LOADED_FEATURES.each do |file|
files_to_reload.each do |reload_name|
if file.end_with?(reload_name)
puts "LOADING #{file}"
load file
break
end
end
end
true
end | ruby | def reload_git_files
files_to_reload =
(`git status`.lines.grep(/modified/).map{|l| l.split(" ").last.gsub('../', '')} +
`git ls-files --others --exclude-standard`.lines).map(&:chomp)
$LOADED_FEATURES.each do |file|
files_to_reload.each do |reload_name|
if file.end_with?(reload_name)
puts "LOADING #{file}"
load file
break
end
end
end
true
end | [
"def",
"reload_git_files",
"files_to_reload",
"=",
"(",
"`",
"`",
".",
"lines",
".",
"grep",
"(",
"/",
"/",
")",
".",
"map",
"{",
"|",
"l",
"|",
"l",
".",
"split",
"(",
"\" \"",
")",
".",
"last",
".",
"gsub",
"(",
"'../'",
",",
"''",
")",
"}",
"+",
"`",
"`",
".",
"lines",
")",
".",
"map",
"(",
"&",
":chomp",
")",
"$LOADED_FEATURES",
".",
"each",
"do",
"|",
"file",
"|",
"files_to_reload",
".",
"each",
"do",
"|",
"reload_name",
"|",
"if",
"file",
".",
"end_with?",
"(",
"reload_name",
")",
"puts",
"\"LOADING #{file}\"",
"load",
"file",
"break",
"end",
"end",
"end",
"true",
"end"
]
| Reloads all required files that have git changes | [
"Reloads",
"all",
"required",
"files",
"that",
"have",
"git",
"changes"
]
| fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745 | https://github.com/calabash/calabash/blob/fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745/lib/calabash/console_helpers.rb#L9-L25 | train |
calabash/calabash | lib/calabash/console_helpers.rb | Calabash.ConsoleHelpers.cal_methods | def cal_methods
c = Class.new(BasicObject) do
include Calabash
end
ConsoleHelpers.puts_unbound_methods(c, 'cal.')
true
end | ruby | def cal_methods
c = Class.new(BasicObject) do
include Calabash
end
ConsoleHelpers.puts_unbound_methods(c, 'cal.')
true
end | [
"def",
"cal_methods",
"c",
"=",
"Class",
".",
"new",
"(",
"BasicObject",
")",
"do",
"include",
"Calabash",
"end",
"ConsoleHelpers",
".",
"puts_unbound_methods",
"(",
"c",
",",
"'cal.'",
")",
"true",
"end"
]
| Outputs all calabash methods | [
"Outputs",
"all",
"calabash",
"methods"
]
| fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745 | https://github.com/calabash/calabash/blob/fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745/lib/calabash/console_helpers.rb#L28-L35 | train |
calabash/calabash | lib/calabash/console_helpers.rb | Calabash.ConsoleHelpers.cal_method | def cal_method(method)
c = Class.new(BasicObject) do
include Calabash
end
ConsoleHelpers.puts_unbound_method(c, method.to_sym, 'cal.')
true
end | ruby | def cal_method(method)
c = Class.new(BasicObject) do
include Calabash
end
ConsoleHelpers.puts_unbound_method(c, method.to_sym, 'cal.')
true
end | [
"def",
"cal_method",
"(",
"method",
")",
"c",
"=",
"Class",
".",
"new",
"(",
"BasicObject",
")",
"do",
"include",
"Calabash",
"end",
"ConsoleHelpers",
".",
"puts_unbound_method",
"(",
"c",
",",
"method",
".",
"to_sym",
",",
"'cal.'",
")",
"true",
"end"
]
| Outputs a calabash method | [
"Outputs",
"a",
"calabash",
"method"
]
| fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745 | https://github.com/calabash/calabash/blob/fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745/lib/calabash/console_helpers.rb#L38-L45 | train |
calabash/calabash | lib/calabash/console_helpers.rb | Calabash.ConsoleHelpers.cal_ios_methods | def cal_ios_methods
c = Class.new(BasicObject) do
include Calabash::IOSInternal
end
ConsoleHelpers.puts_unbound_methods(c, 'cal_ios.')
true
end | ruby | def cal_ios_methods
c = Class.new(BasicObject) do
include Calabash::IOSInternal
end
ConsoleHelpers.puts_unbound_methods(c, 'cal_ios.')
true
end | [
"def",
"cal_ios_methods",
"c",
"=",
"Class",
".",
"new",
"(",
"BasicObject",
")",
"do",
"include",
"Calabash",
"::",
"IOSInternal",
"end",
"ConsoleHelpers",
".",
"puts_unbound_methods",
"(",
"c",
",",
"'cal_ios.'",
")",
"true",
"end"
]
| Outputs all calabash iOS methods | [
"Outputs",
"all",
"calabash",
"iOS",
"methods"
]
| fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745 | https://github.com/calabash/calabash/blob/fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745/lib/calabash/console_helpers.rb#L48-L55 | train |
calabash/calabash | lib/calabash/console_helpers.rb | Calabash.ConsoleHelpers.cal_android_methods | def cal_android_methods
c = Class.new(BasicObject) do
include Calabash::AndroidInternal
end
ConsoleHelpers.puts_unbound_methods(c, 'cal_android.')
true
end | ruby | def cal_android_methods
c = Class.new(BasicObject) do
include Calabash::AndroidInternal
end
ConsoleHelpers.puts_unbound_methods(c, 'cal_android.')
true
end | [
"def",
"cal_android_methods",
"c",
"=",
"Class",
".",
"new",
"(",
"BasicObject",
")",
"do",
"include",
"Calabash",
"::",
"AndroidInternal",
"end",
"ConsoleHelpers",
".",
"puts_unbound_methods",
"(",
"c",
",",
"'cal_android.'",
")",
"true",
"end"
]
| Outputs all calabash Android methods | [
"Outputs",
"all",
"calabash",
"Android",
"methods"
]
| fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745 | https://github.com/calabash/calabash/blob/fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745/lib/calabash/console_helpers.rb#L68-L75 | train |
calabash/calabash | lib/calabash/console_helpers.rb | Calabash.ConsoleHelpers.tree | def tree
ConsoleHelpers.dump(Calabash::Internal.with_current_target {|target| target.dump})
true
end | ruby | def tree
ConsoleHelpers.dump(Calabash::Internal.with_current_target {|target| target.dump})
true
end | [
"def",
"tree",
"ConsoleHelpers",
".",
"dump",
"(",
"Calabash",
"::",
"Internal",
".",
"with_current_target",
"{",
"|",
"target",
"|",
"target",
".",
"dump",
"}",
")",
"true",
"end"
]
| Outputs all visible elements as a tree. | [
"Outputs",
"all",
"visible",
"elements",
"as",
"a",
"tree",
"."
]
| fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745 | https://github.com/calabash/calabash/blob/fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745/lib/calabash/console_helpers.rb#L88-L91 | train |
calabash/calabash | lib/calabash/console_helpers.rb | Calabash.ConsoleHelpers.verbose | def verbose
if Calabash::Logger.log_levels.include?(:debug)
puts Color.blue('Debug logging is already turned on.')
else
Calabash::Logger.log_levels << :debug
puts Color.blue('Turned on debug logging.')
end
true
end | ruby | def verbose
if Calabash::Logger.log_levels.include?(:debug)
puts Color.blue('Debug logging is already turned on.')
else
Calabash::Logger.log_levels << :debug
puts Color.blue('Turned on debug logging.')
end
true
end | [
"def",
"verbose",
"if",
"Calabash",
"::",
"Logger",
".",
"log_levels",
".",
"include?",
"(",
":debug",
")",
"puts",
"Color",
".",
"blue",
"(",
"'Debug logging is already turned on.'",
")",
"else",
"Calabash",
"::",
"Logger",
".",
"log_levels",
"<<",
":debug",
"puts",
"Color",
".",
"blue",
"(",
"'Turned on debug logging.'",
")",
"end",
"true",
"end"
]
| Turn on debug logging. | [
"Turn",
"on",
"debug",
"logging",
"."
]
| fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745 | https://github.com/calabash/calabash/blob/fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745/lib/calabash/console_helpers.rb#L147-L156 | train |
calabash/calabash | lib/calabash/console_helpers.rb | Calabash.ConsoleHelpers.quiet | def quiet
if Calabash::Logger.log_levels.include?(:debug)
puts Color.blue('Turned off debug logging.')
Calabash::Logger.log_levels.delete(:debug)
else
puts Color.blue('Debug logging is already turned off.')
end
true
end | ruby | def quiet
if Calabash::Logger.log_levels.include?(:debug)
puts Color.blue('Turned off debug logging.')
Calabash::Logger.log_levels.delete(:debug)
else
puts Color.blue('Debug logging is already turned off.')
end
true
end | [
"def",
"quiet",
"if",
"Calabash",
"::",
"Logger",
".",
"log_levels",
".",
"include?",
"(",
":debug",
")",
"puts",
"Color",
".",
"blue",
"(",
"'Turned off debug logging.'",
")",
"Calabash",
"::",
"Logger",
".",
"log_levels",
".",
"delete",
"(",
":debug",
")",
"else",
"puts",
"Color",
".",
"blue",
"(",
"'Debug logging is already turned off.'",
")",
"end",
"true",
"end"
]
| Turn off debug logging. | [
"Turn",
"off",
"debug",
"logging",
"."
]
| fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745 | https://github.com/calabash/calabash/blob/fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745/lib/calabash/console_helpers.rb#L159-L168 | train |
dicom/ruby-dicom | lib/dicom/stream.rb | DICOM.Stream.decode | def decode(length, type)
raise ArgumentError, "Invalid argument length. Expected Integer, got #{length.class}" unless length.is_a?(Integer)
raise ArgumentError, "Invalid argument type. Expected string, got #{type.class}" unless type.is_a?(String)
value = nil
if (@index + length) <= @string.length
# There are sufficient bytes remaining to extract the value:
if type == 'AT'
# We need to guard ourselves against the case where a string contains an invalid 'AT' value:
if length == 4
value = decode_tag
else
# Invalid. Just return nil.
skip(length)
end
else
# Decode the binary string and return value:
value = @string.slice(@index, length).unpack(vr_to_str(type))
# If the result is an array of one element, return the element instead of the array.
# If result is contained in a multi-element array, the original array is returned.
if value.length == 1
value = value[0]
# If value is a string, strip away possible trailing whitespace:
value = value.rstrip if value.is_a?(String)
end
# Update our position in the string:
skip(length)
end
end
value
end | ruby | def decode(length, type)
raise ArgumentError, "Invalid argument length. Expected Integer, got #{length.class}" unless length.is_a?(Integer)
raise ArgumentError, "Invalid argument type. Expected string, got #{type.class}" unless type.is_a?(String)
value = nil
if (@index + length) <= @string.length
# There are sufficient bytes remaining to extract the value:
if type == 'AT'
# We need to guard ourselves against the case where a string contains an invalid 'AT' value:
if length == 4
value = decode_tag
else
# Invalid. Just return nil.
skip(length)
end
else
# Decode the binary string and return value:
value = @string.slice(@index, length).unpack(vr_to_str(type))
# If the result is an array of one element, return the element instead of the array.
# If result is contained in a multi-element array, the original array is returned.
if value.length == 1
value = value[0]
# If value is a string, strip away possible trailing whitespace:
value = value.rstrip if value.is_a?(String)
end
# Update our position in the string:
skip(length)
end
end
value
end | [
"def",
"decode",
"(",
"length",
",",
"type",
")",
"raise",
"ArgumentError",
",",
"\"Invalid argument length. Expected Integer, got #{length.class}\"",
"unless",
"length",
".",
"is_a?",
"(",
"Integer",
")",
"raise",
"ArgumentError",
",",
"\"Invalid argument type. Expected string, got #{type.class}\"",
"unless",
"type",
".",
"is_a?",
"(",
"String",
")",
"value",
"=",
"nil",
"if",
"(",
"@index",
"+",
"length",
")",
"<=",
"@string",
".",
"length",
"if",
"type",
"==",
"'AT'",
"if",
"length",
"==",
"4",
"value",
"=",
"decode_tag",
"else",
"skip",
"(",
"length",
")",
"end",
"else",
"value",
"=",
"@string",
".",
"slice",
"(",
"@index",
",",
"length",
")",
".",
"unpack",
"(",
"vr_to_str",
"(",
"type",
")",
")",
"if",
"value",
".",
"length",
"==",
"1",
"value",
"=",
"value",
"[",
"0",
"]",
"value",
"=",
"value",
".",
"rstrip",
"if",
"value",
".",
"is_a?",
"(",
"String",
")",
"end",
"skip",
"(",
"length",
")",
"end",
"end",
"value",
"end"
]
| Decodes a section of the instance string.
The instance index is offset in accordance with the length read.
@note If multiple numbers are decoded, these are returned in an array.
@param [Integer] length the string length to be decoded
@param [String] type the type (vr) of data to decode
@return [String, Integer, Float, Array] the formatted (decoded) data | [
"Decodes",
"a",
"section",
"of",
"the",
"instance",
"string",
".",
"The",
"instance",
"index",
"is",
"offset",
"in",
"accordance",
"with",
"the",
"length",
"read",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/stream.rb#L63-L92 | train |
dicom/ruby-dicom | lib/dicom/stream.rb | DICOM.Stream.decode_tag | def decode_tag
length = 4
tag = nil
if (@index + length) <= @string.length
# There are sufficient bytes remaining to extract a full tag:
str = @string.slice(@index, length).unpack(@hex)[0].upcase
if @equal_endian
tag = "#{str[2..3]}#{str[0..1]},#{str[6..7]}#{str[4..5]}"
else
tag = "#{str[0..3]},#{str[4..7]}"
end
# Update our position in the string:
skip(length)
end
tag
end | ruby | def decode_tag
length = 4
tag = nil
if (@index + length) <= @string.length
# There are sufficient bytes remaining to extract a full tag:
str = @string.slice(@index, length).unpack(@hex)[0].upcase
if @equal_endian
tag = "#{str[2..3]}#{str[0..1]},#{str[6..7]}#{str[4..5]}"
else
tag = "#{str[0..3]},#{str[4..7]}"
end
# Update our position in the string:
skip(length)
end
tag
end | [
"def",
"decode_tag",
"length",
"=",
"4",
"tag",
"=",
"nil",
"if",
"(",
"@index",
"+",
"length",
")",
"<=",
"@string",
".",
"length",
"str",
"=",
"@string",
".",
"slice",
"(",
"@index",
",",
"length",
")",
".",
"unpack",
"(",
"@hex",
")",
"[",
"0",
"]",
".",
"upcase",
"if",
"@equal_endian",
"tag",
"=",
"\"#{str[2..3]}#{str[0..1]},#{str[6..7]}#{str[4..5]}\"",
"else",
"tag",
"=",
"\"#{str[0..3]},#{str[4..7]}\"",
"end",
"skip",
"(",
"length",
")",
"end",
"tag",
"end"
]
| Decodes 4 bytes of the instance string and formats it as a ruby-dicom tag string.
@return [String, NilClass] a formatted tag string ('GGGG,EEEE'), or nil (e.g. if at end of string) | [
"Decodes",
"4",
"bytes",
"of",
"the",
"instance",
"string",
"and",
"formats",
"it",
"as",
"a",
"ruby",
"-",
"dicom",
"tag",
"string",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/stream.rb#L111-L126 | train |
dicom/ruby-dicom | lib/dicom/stream.rb | DICOM.Stream.encode | def encode(value, type)
raise ArgumentError, "Invalid argument type. Expected string, got #{type.class}" unless type.is_a?(String)
value = [value] unless value.is_a?(Array)
return value.pack(vr_to_str(type))
end | ruby | def encode(value, type)
raise ArgumentError, "Invalid argument type. Expected string, got #{type.class}" unless type.is_a?(String)
value = [value] unless value.is_a?(Array)
return value.pack(vr_to_str(type))
end | [
"def",
"encode",
"(",
"value",
",",
"type",
")",
"raise",
"ArgumentError",
",",
"\"Invalid argument type. Expected string, got #{type.class}\"",
"unless",
"type",
".",
"is_a?",
"(",
"String",
")",
"value",
"=",
"[",
"value",
"]",
"unless",
"value",
".",
"is_a?",
"(",
"Array",
")",
"return",
"value",
".",
"pack",
"(",
"vr_to_str",
"(",
"type",
")",
")",
"end"
]
| Encodes a given value to a binary string.
@param [String, Integer, Float, Array] value a formatted value (String, Integer, etc..) or an array of numbers
@param [String] type the type (vr) of data to encode
@return [String] an encoded binary string | [
"Encodes",
"a",
"given",
"value",
"to",
"a",
"binary",
"string",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/stream.rb#L134-L138 | train |
dicom/ruby-dicom | lib/dicom/stream.rb | DICOM.Stream.encode_string_with_trailing_spaces | def encode_string_with_trailing_spaces(string, target_length)
length = string.length
if length < target_length
return "#{[string].pack(@str)}#{['20'*(target_length-length)].pack(@hex)}"
elsif length == target_length
return [string].pack(@str)
else
raise "The specified string is longer than the allowed maximum length (String: #{string}, Target length: #{target_length})."
end
end | ruby | def encode_string_with_trailing_spaces(string, target_length)
length = string.length
if length < target_length
return "#{[string].pack(@str)}#{['20'*(target_length-length)].pack(@hex)}"
elsif length == target_length
return [string].pack(@str)
else
raise "The specified string is longer than the allowed maximum length (String: #{string}, Target length: #{target_length})."
end
end | [
"def",
"encode_string_with_trailing_spaces",
"(",
"string",
",",
"target_length",
")",
"length",
"=",
"string",
".",
"length",
"if",
"length",
"<",
"target_length",
"return",
"\"#{[string].pack(@str)}#{['20'*(target_length-length)].pack(@hex)}\"",
"elsif",
"length",
"==",
"target_length",
"return",
"[",
"string",
"]",
".",
"pack",
"(",
"@str",
")",
"else",
"raise",
"\"The specified string is longer than the allowed maximum length (String: #{string}, Target length: #{target_length}).\"",
"end",
"end"
]
| Appends a string with trailling spaces to achieve a target length, and encodes it to a binary string.
@param [String] string a string to be padded
@param [Integer] target_length the target length of the string
@return [String] an encoded binary string | [
"Appends",
"a",
"string",
"with",
"trailling",
"spaces",
"to",
"achieve",
"a",
"target",
"length",
"and",
"encodes",
"it",
"to",
"a",
"binary",
"string",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/stream.rb#L166-L175 | train |
dicom/ruby-dicom | lib/dicom/stream.rb | DICOM.Stream.encode_value | def encode_value(value, vr)
if vr == 'AT'
bin = encode_tag(value)
else
# Make sure the value is in an array:
value = [value] unless value.is_a?(Array)
# Get the proper pack string:
type = vr_to_str(vr)
# Encode:
bin = value.pack(type)
# Add an empty byte if the resulting binary has an odd length:
bin = "#{bin}#{@pad_byte[vr]}" if bin.length.odd?
end
return bin
end | ruby | def encode_value(value, vr)
if vr == 'AT'
bin = encode_tag(value)
else
# Make sure the value is in an array:
value = [value] unless value.is_a?(Array)
# Get the proper pack string:
type = vr_to_str(vr)
# Encode:
bin = value.pack(type)
# Add an empty byte if the resulting binary has an odd length:
bin = "#{bin}#{@pad_byte[vr]}" if bin.length.odd?
end
return bin
end | [
"def",
"encode_value",
"(",
"value",
",",
"vr",
")",
"if",
"vr",
"==",
"'AT'",
"bin",
"=",
"encode_tag",
"(",
"value",
")",
"else",
"value",
"=",
"[",
"value",
"]",
"unless",
"value",
".",
"is_a?",
"(",
"Array",
")",
"type",
"=",
"vr_to_str",
"(",
"vr",
")",
"bin",
"=",
"value",
".",
"pack",
"(",
"type",
")",
"bin",
"=",
"\"#{bin}#{@pad_byte[vr]}\"",
"if",
"bin",
".",
"length",
".",
"odd?",
"end",
"return",
"bin",
"end"
]
| Encodes a value, and if the the resulting binary string has an
odd length, appends a proper padding byte to make it even length.
@param [String, Integer, Float, Array] value a formatted value (String, Integer, etc..) or an array of numbers
@param [String] vr the value representation of data to encode
@return [String] the encoded binary string | [
"Encodes",
"a",
"value",
"and",
"if",
"the",
"the",
"resulting",
"binary",
"string",
"has",
"an",
"odd",
"length",
"appends",
"a",
"proper",
"padding",
"byte",
"to",
"make",
"it",
"even",
"length",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/stream.rb#L195-L209 | train |
calabash/calabash | lib/calabash/interactions.rb | Calabash.Interactions.backdoor | def backdoor(name, *arguments)
Calabash::Internal.with_current_target {|target| target.backdoor(name, *arguments)}
end | ruby | def backdoor(name, *arguments)
Calabash::Internal.with_current_target {|target| target.backdoor(name, *arguments)}
end | [
"def",
"backdoor",
"(",
"name",
",",
"*",
"arguments",
")",
"Calabash",
"::",
"Internal",
".",
"with_current_target",
"{",
"|",
"target",
"|",
"target",
".",
"backdoor",
"(",
"name",
",",
"*",
"arguments",
")",
"}",
"end"
]
| Invoke a method in your application.
This is an escape hatch for calling an arbitrary hook inside
(the test build) of your app. Commonly used to "go around" the UI for
speed purposes or reset the app to a good known state.
For iOS this method calls a method on the app's AppDelegate object.
For Android this method tries to invoke a method on the current Activity
instance. If the method is not defined in the current activity, Calabash
tries to invoke the method on the current Application instance.
@note The Android implementation accepts any number of arguments, of any
type including null (Ruby nil). The iOS implementation does not accept
more than one argument, of the type NSString (Ruby String) or
NSDictionary (Ruby Hash).
### For iOS
You must create a method on you app delegate of the form:
- (NSString *) calabashBackdoor:(NSString *)aIgnorable;
or if you want to pass parameters
- (NSString *) calabashBackdoor:(NSDictionary *)params;
### For Android
You must create a public method in your current Activity or Application.
public <return type> calabashBackdoor(String param1, int param2)
@example
# iOS
backdoor('calabashBackdoor:', '')
@example
# iOS
backdoor('calabashBackdoor:', {example:'param'})
@example
# Android
backdoor('calabashBackdoor', 'first argument', 2)
@param [String] name The selector/method name.
@param [Object] arguments A comma separated list of arguments to be
passed to the backdoor selector/method.
@return [Object] the result of performing the selector/method with the
arguments (serialized) | [
"Invoke",
"a",
"method",
"in",
"your",
"application",
"."
]
| fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745 | https://github.com/calabash/calabash/blob/fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745/lib/calabash/interactions.rb#L128-L130 | train |
dicom/ruby-dicom | lib/dicom/d_server.rb | DICOM.DServer.add_abstract_syntax | def add_abstract_syntax(uid)
lib_uid = LIBRARY.uid(uid)
raise "Invalid/unknown UID: #{uid}" unless lib_uid
@accepted_abstract_syntaxes[uid] = lib_uid.name
end | ruby | def add_abstract_syntax(uid)
lib_uid = LIBRARY.uid(uid)
raise "Invalid/unknown UID: #{uid}" unless lib_uid
@accepted_abstract_syntaxes[uid] = lib_uid.name
end | [
"def",
"add_abstract_syntax",
"(",
"uid",
")",
"lib_uid",
"=",
"LIBRARY",
".",
"uid",
"(",
"uid",
")",
"raise",
"\"Invalid/unknown UID: #{uid}\"",
"unless",
"lib_uid",
"@accepted_abstract_syntaxes",
"[",
"uid",
"]",
"=",
"lib_uid",
".",
"name",
"end"
]
| Creates a DServer instance.
@note To customize logging behaviour, refer to the Logging module documentation.
@param [Integer] port the network port to be used
@param [Hash] options the options to use for the DICOM server
@option options [String] :file_handler a customized FileHandler class to use instead of the default FileHandler
@option options [String] :host the hostname that the TCPServer binds to (defaults to '0.0.0.0')
@option options [String] :host_ae the name of the server (application entity)
@option options [String] :max_package_size the maximum allowed size of network packages (in bytes)
@option options [String] :timeout the number of seconds the server will wait on an answer from a client before aborting the communication
@example Create a server using default settings
s = DICOM::DServer.new
@example Create a server with a specific host name and a custom buildt file handler
require_relative 'my_file_handler'
server = DICOM::DServer.new(104, :host_ae => "RUBY_SERVER", :file_handler => DICOM::MyFileHandler)
Adds an abstract syntax to the list of abstract syntaxes that the server will accept.
@param [String] uid an abstract syntax UID | [
"Creates",
"a",
"DServer",
"instance",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/d_server.rb#L89-L93 | train |
dicom/ruby-dicom | lib/dicom/d_server.rb | DICOM.DServer.add_transfer_syntax | def add_transfer_syntax(uid)
lib_uid = LIBRARY.uid(uid)
raise "Invalid/unknown UID: #{uid}" unless lib_uid
@accepted_transfer_syntaxes[uid] = lib_uid.name
end | ruby | def add_transfer_syntax(uid)
lib_uid = LIBRARY.uid(uid)
raise "Invalid/unknown UID: #{uid}" unless lib_uid
@accepted_transfer_syntaxes[uid] = lib_uid.name
end | [
"def",
"add_transfer_syntax",
"(",
"uid",
")",
"lib_uid",
"=",
"LIBRARY",
".",
"uid",
"(",
"uid",
")",
"raise",
"\"Invalid/unknown UID: #{uid}\"",
"unless",
"lib_uid",
"@accepted_transfer_syntaxes",
"[",
"uid",
"]",
"=",
"lib_uid",
".",
"name",
"end"
]
| Adds a transfer syntax to the list of transfer syntaxes that the server will accept.
@param [String] uid a transfer syntax UID | [
"Adds",
"a",
"transfer",
"syntax",
"to",
"the",
"list",
"of",
"transfer",
"syntaxes",
"that",
"the",
"server",
"will",
"accept",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/d_server.rb#L99-L103 | train |
dicom/ruby-dicom | lib/dicom/d_server.rb | DICOM.DServer.print_abstract_syntaxes | def print_abstract_syntaxes
# Determine length of longest key to ensure pretty print:
max_uid = @accepted_abstract_syntaxes.keys.collect{|k| k.length}.max
puts "Abstract syntaxes which are accepted by this SCP:"
@accepted_abstract_syntaxes.sort.each do |pair|
puts "#{pair[0]}#{' '*(max_uid-pair[0].length)} #{pair[1]}"
end
end | ruby | def print_abstract_syntaxes
# Determine length of longest key to ensure pretty print:
max_uid = @accepted_abstract_syntaxes.keys.collect{|k| k.length}.max
puts "Abstract syntaxes which are accepted by this SCP:"
@accepted_abstract_syntaxes.sort.each do |pair|
puts "#{pair[0]}#{' '*(max_uid-pair[0].length)} #{pair[1]}"
end
end | [
"def",
"print_abstract_syntaxes",
"max_uid",
"=",
"@accepted_abstract_syntaxes",
".",
"keys",
".",
"collect",
"{",
"|",
"k",
"|",
"k",
".",
"length",
"}",
".",
"max",
"puts",
"\"Abstract syntaxes which are accepted by this SCP:\"",
"@accepted_abstract_syntaxes",
".",
"sort",
".",
"each",
"do",
"|",
"pair",
"|",
"puts",
"\"#{pair[0]}#{' '*(max_uid-pair[0].length)} #{pair[1]}\"",
"end",
"end"
]
| Prints the list of accepted abstract syntaxes to the screen. | [
"Prints",
"the",
"list",
"of",
"accepted",
"abstract",
"syntaxes",
"to",
"the",
"screen",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/d_server.rb#L107-L114 | train |
calabash/calabash | lib/calabash/wait.rb | Calabash.Wait.wait_for_view | def wait_for_view(query,
timeout: Calabash::Wait.default_options[:timeout],
timeout_message: nil,
retry_frequency: Calabash::Wait.default_options[:retry_frequency])
if query.nil?
raise ArgumentError, 'Query cannot be nil'
end
timeout_message ||= lambda do |wait_options|
"Waited #{wait_options[:timeout]} seconds for #{Wait.parse_query_list(query)} to match a view"
end
wait_for(timeout_message,
timeout: timeout,
retry_frequency: retry_frequency,
exception_class: ViewNotFoundError) do
result = query(query)
!result.empty? && result
end.first
end | ruby | def wait_for_view(query,
timeout: Calabash::Wait.default_options[:timeout],
timeout_message: nil,
retry_frequency: Calabash::Wait.default_options[:retry_frequency])
if query.nil?
raise ArgumentError, 'Query cannot be nil'
end
timeout_message ||= lambda do |wait_options|
"Waited #{wait_options[:timeout]} seconds for #{Wait.parse_query_list(query)} to match a view"
end
wait_for(timeout_message,
timeout: timeout,
retry_frequency: retry_frequency,
exception_class: ViewNotFoundError) do
result = query(query)
!result.empty? && result
end.first
end | [
"def",
"wait_for_view",
"(",
"query",
",",
"timeout",
":",
"Calabash",
"::",
"Wait",
".",
"default_options",
"[",
":timeout",
"]",
",",
"timeout_message",
":",
"nil",
",",
"retry_frequency",
":",
"Calabash",
"::",
"Wait",
".",
"default_options",
"[",
":retry_frequency",
"]",
")",
"if",
"query",
".",
"nil?",
"raise",
"ArgumentError",
",",
"'Query cannot be nil'",
"end",
"timeout_message",
"||=",
"lambda",
"do",
"|",
"wait_options",
"|",
"\"Waited #{wait_options[:timeout]} seconds for #{Wait.parse_query_list(query)} to match a view\"",
"end",
"wait_for",
"(",
"timeout_message",
",",
"timeout",
":",
"timeout",
",",
"retry_frequency",
":",
"retry_frequency",
",",
"exception_class",
":",
"ViewNotFoundError",
")",
"do",
"result",
"=",
"query",
"(",
"query",
")",
"!",
"result",
".",
"empty?",
"&&",
"result",
"end",
".",
"first",
"end"
]
| Waits for `query` to match one or more views.
@example
cal.wait_for_view({marked: 'mark'})
@example
cal.wait_for_view({marked: 'login'},
timeout_message: "Did not see login button")
@example
text = cal.wait_for_view("myview")['text']
@see Calabash::Wait#wait_for for optional parameters
@param [String, Hash, Calabash::Query] query Query to match view
@return [Hash] The first view matching `query`.
@raise [ViewNotFoundError] If `query` do not match at least one view. | [
"Waits",
"for",
"query",
"to",
"match",
"one",
"or",
"more",
"views",
"."
]
| fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745 | https://github.com/calabash/calabash/blob/fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745/lib/calabash/wait.rb#L187-L206 | train |
calabash/calabash | lib/calabash/wait.rb | Calabash.Wait.wait_for_views | def wait_for_views(*queries,
timeout: Calabash::Wait.default_options[:timeout],
timeout_message: nil,
retry_frequency: Calabash::Wait.default_options[:retry_frequency])
if queries.nil? || queries.any?(&:nil?)
raise ArgumentError, 'Query cannot be nil'
end
timeout_message ||= lambda do |wait_options|
"Waited #{wait_options[:timeout]} seconds for #{Wait.parse_query_list(queries)} to each match a view"
end
wait_for(timeout_message,
timeout: timeout,
retry_frequency: retry_frequency,
exception_class: ViewNotFoundError) do
views_exist?(*queries)
end
# Do not return the value of views_exist?(queries) as it clutters
# a console environment
true
end | ruby | def wait_for_views(*queries,
timeout: Calabash::Wait.default_options[:timeout],
timeout_message: nil,
retry_frequency: Calabash::Wait.default_options[:retry_frequency])
if queries.nil? || queries.any?(&:nil?)
raise ArgumentError, 'Query cannot be nil'
end
timeout_message ||= lambda do |wait_options|
"Waited #{wait_options[:timeout]} seconds for #{Wait.parse_query_list(queries)} to each match a view"
end
wait_for(timeout_message,
timeout: timeout,
retry_frequency: retry_frequency,
exception_class: ViewNotFoundError) do
views_exist?(*queries)
end
# Do not return the value of views_exist?(queries) as it clutters
# a console environment
true
end | [
"def",
"wait_for_views",
"(",
"*",
"queries",
",",
"timeout",
":",
"Calabash",
"::",
"Wait",
".",
"default_options",
"[",
":timeout",
"]",
",",
"timeout_message",
":",
"nil",
",",
"retry_frequency",
":",
"Calabash",
"::",
"Wait",
".",
"default_options",
"[",
":retry_frequency",
"]",
")",
"if",
"queries",
".",
"nil?",
"||",
"queries",
".",
"any?",
"(",
"&",
":nil?",
")",
"raise",
"ArgumentError",
",",
"'Query cannot be nil'",
"end",
"timeout_message",
"||=",
"lambda",
"do",
"|",
"wait_options",
"|",
"\"Waited #{wait_options[:timeout]} seconds for #{Wait.parse_query_list(queries)} to each match a view\"",
"end",
"wait_for",
"(",
"timeout_message",
",",
"timeout",
":",
"timeout",
",",
"retry_frequency",
":",
"retry_frequency",
",",
"exception_class",
":",
"ViewNotFoundError",
")",
"do",
"views_exist?",
"(",
"*",
"queries",
")",
"end",
"true",
"end"
]
| Waits for all `queries` to simultaneously match at least one view.
@example
cal.wait_for_views({id: 'foo'}, {id: 'bar'})
@see Calabash::Wait#wait_for for optional parameters
@param [String, Hash, Calabash::Query] queries List of queries or a
query.
@return The returned value is undefined
@raise [ViewNotFoundError] If `queries` do not all match at least one
view. | [
"Waits",
"for",
"all",
"queries",
"to",
"simultaneously",
"match",
"at",
"least",
"one",
"view",
"."
]
| fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745 | https://github.com/calabash/calabash/blob/fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745/lib/calabash/wait.rb#L220-L242 | train |
calabash/calabash | lib/calabash/wait.rb | Calabash.Wait.wait_for_no_view | def wait_for_no_view(query,
timeout: Calabash::Wait.default_options[:timeout],
timeout_message: nil,
retry_frequency: Calabash::Wait.default_options[:retry_frequency])
if query.nil?
raise ArgumentError, 'Query cannot be nil'
end
timeout_message ||= lambda do |wait_options|
"Waited #{wait_options[:timeout]} seconds for #{Wait.parse_query_list(query)} to not match any view"
end
wait_for(timeout_message,
timeout: timeout,
retry_frequency: retry_frequency,
exception_class: ViewFoundError) do
!view_exists?(query)
end
end | ruby | def wait_for_no_view(query,
timeout: Calabash::Wait.default_options[:timeout],
timeout_message: nil,
retry_frequency: Calabash::Wait.default_options[:retry_frequency])
if query.nil?
raise ArgumentError, 'Query cannot be nil'
end
timeout_message ||= lambda do |wait_options|
"Waited #{wait_options[:timeout]} seconds for #{Wait.parse_query_list(query)} to not match any view"
end
wait_for(timeout_message,
timeout: timeout,
retry_frequency: retry_frequency,
exception_class: ViewFoundError) do
!view_exists?(query)
end
end | [
"def",
"wait_for_no_view",
"(",
"query",
",",
"timeout",
":",
"Calabash",
"::",
"Wait",
".",
"default_options",
"[",
":timeout",
"]",
",",
"timeout_message",
":",
"nil",
",",
"retry_frequency",
":",
"Calabash",
"::",
"Wait",
".",
"default_options",
"[",
":retry_frequency",
"]",
")",
"if",
"query",
".",
"nil?",
"raise",
"ArgumentError",
",",
"'Query cannot be nil'",
"end",
"timeout_message",
"||=",
"lambda",
"do",
"|",
"wait_options",
"|",
"\"Waited #{wait_options[:timeout]} seconds for #{Wait.parse_query_list(query)} to not match any view\"",
"end",
"wait_for",
"(",
"timeout_message",
",",
"timeout",
":",
"timeout",
",",
"retry_frequency",
":",
"retry_frequency",
",",
"exception_class",
":",
"ViewFoundError",
")",
"do",
"!",
"view_exists?",
"(",
"query",
")",
"end",
"end"
]
| Waits for `query` not to match any views
@example
cal.wait_for_no_view({marked: 'mark'})
@example
cal.wait_for_no_view({marked: 'login'},
timeout_message: "Login button did not disappear")
@see Calabash::Wait#wait_for for optional parameters
@param [String, Hash, Calabash::Query] query Query to match view
@raise [ViewFoundError] If `query` do not match at least one view. | [
"Waits",
"for",
"query",
"not",
"to",
"match",
"any",
"views"
]
| fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745 | https://github.com/calabash/calabash/blob/fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745/lib/calabash/wait.rb#L257-L275 | train |
calabash/calabash | lib/calabash/wait.rb | Calabash.Wait.wait_for_no_views | def wait_for_no_views(*queries,
timeout: Calabash::Wait.default_options[:timeout],
timeout_message: nil,
retry_frequency: Calabash::Wait.default_options[:retry_frequency])
if queries.nil? || queries.any?(&:nil?)
raise ArgumentError, 'Query cannot be nil'
end
timeout_message ||= lambda do |wait_options|
"Waited #{wait_options[:timeout]} seconds for #{Wait.parse_query_list(queries)} to each not match any view"
end
wait_for(timeout_message,
timeout: timeout,
retry_frequency: retry_frequency,
exception_class: ViewFoundError) do
!views_exist?(*queries)
end
end | ruby | def wait_for_no_views(*queries,
timeout: Calabash::Wait.default_options[:timeout],
timeout_message: nil,
retry_frequency: Calabash::Wait.default_options[:retry_frequency])
if queries.nil? || queries.any?(&:nil?)
raise ArgumentError, 'Query cannot be nil'
end
timeout_message ||= lambda do |wait_options|
"Waited #{wait_options[:timeout]} seconds for #{Wait.parse_query_list(queries)} to each not match any view"
end
wait_for(timeout_message,
timeout: timeout,
retry_frequency: retry_frequency,
exception_class: ViewFoundError) do
!views_exist?(*queries)
end
end | [
"def",
"wait_for_no_views",
"(",
"*",
"queries",
",",
"timeout",
":",
"Calabash",
"::",
"Wait",
".",
"default_options",
"[",
":timeout",
"]",
",",
"timeout_message",
":",
"nil",
",",
"retry_frequency",
":",
"Calabash",
"::",
"Wait",
".",
"default_options",
"[",
":retry_frequency",
"]",
")",
"if",
"queries",
".",
"nil?",
"||",
"queries",
".",
"any?",
"(",
"&",
":nil?",
")",
"raise",
"ArgumentError",
",",
"'Query cannot be nil'",
"end",
"timeout_message",
"||=",
"lambda",
"do",
"|",
"wait_options",
"|",
"\"Waited #{wait_options[:timeout]} seconds for #{Wait.parse_query_list(queries)} to each not match any view\"",
"end",
"wait_for",
"(",
"timeout_message",
",",
"timeout",
":",
"timeout",
",",
"retry_frequency",
":",
"retry_frequency",
",",
"exception_class",
":",
"ViewFoundError",
")",
"do",
"!",
"views_exist?",
"(",
"*",
"queries",
")",
"end",
"end"
]
| Waits for all `queries` to simultaneously match no views
@example
cal.wait_for_no_views({id: 'foo'}, {id: 'bar'})
@see Calabash::Wait#wait_for for optional parameters
@param [String, Hash, Calabash::Query] queries List of queries or a
query.
@raise [ViewNotFoundError] If `queries` do not all match at least one
view. | [
"Waits",
"for",
"all",
"queries",
"to",
"simultaneously",
"match",
"no",
"views"
]
| fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745 | https://github.com/calabash/calabash/blob/fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745/lib/calabash/wait.rb#L288-L306 | train |
calabash/calabash | lib/calabash/wait.rb | Calabash.Wait.view_exists? | def view_exists?(query)
if query.nil?
raise ArgumentError, 'Query cannot be nil'
end
result = query(query)
!result.empty?
end | ruby | def view_exists?(query)
if query.nil?
raise ArgumentError, 'Query cannot be nil'
end
result = query(query)
!result.empty?
end | [
"def",
"view_exists?",
"(",
"query",
")",
"if",
"query",
".",
"nil?",
"raise",
"ArgumentError",
",",
"'Query cannot be nil'",
"end",
"result",
"=",
"query",
"(",
"query",
")",
"!",
"result",
".",
"empty?",
"end"
]
| Does the given `query` match at least one view?
@param [String, Hash, Calabash::Query] query Query to match view
@return [Boolean] Returns true if the `query` matches at least one view
@raise [ArgumentError] If given an invalid `query` | [
"Does",
"the",
"given",
"query",
"match",
"at",
"least",
"one",
"view?"
]
| fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745 | https://github.com/calabash/calabash/blob/fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745/lib/calabash/wait.rb#L313-L321 | train |
calabash/calabash | lib/calabash/wait.rb | Calabash.Wait.views_exist? | def views_exist?(*queries)
if queries.nil? || queries.any?(&:nil?)
raise ArgumentError, 'Query cannot be nil'
end
results = queries.map{|query| view_exists?(query)}
results.all?
end | ruby | def views_exist?(*queries)
if queries.nil? || queries.any?(&:nil?)
raise ArgumentError, 'Query cannot be nil'
end
results = queries.map{|query| view_exists?(query)}
results.all?
end | [
"def",
"views_exist?",
"(",
"*",
"queries",
")",
"if",
"queries",
".",
"nil?",
"||",
"queries",
".",
"any?",
"(",
"&",
":nil?",
")",
"raise",
"ArgumentError",
",",
"'Query cannot be nil'",
"end",
"results",
"=",
"queries",
".",
"map",
"{",
"|",
"query",
"|",
"view_exists?",
"(",
"query",
")",
"}",
"results",
".",
"all?",
"end"
]
| Does the given `queries` all match at least one view?
@param [String, Hash, Calabash::Query] queries List of queries or a
query
@return [Boolean] Returns true if the `queries` all match at least one
view
@raise [ArgumentError] If given an invalid list of queries | [
"Does",
"the",
"given",
"queries",
"all",
"match",
"at",
"least",
"one",
"view?"
]
| fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745 | https://github.com/calabash/calabash/blob/fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745/lib/calabash/wait.rb#L330-L338 | train |
calabash/calabash | lib/calabash/wait.rb | Calabash.Wait.expect_view | def expect_view(query)
if query.nil?
raise ArgumentError, 'Query cannot be nil'
end
unless view_exists?(query)
raise ViewNotFoundError,
"No view matched #{Wait.parse_query_list(query)}"
end
true
end | ruby | def expect_view(query)
if query.nil?
raise ArgumentError, 'Query cannot be nil'
end
unless view_exists?(query)
raise ViewNotFoundError,
"No view matched #{Wait.parse_query_list(query)}"
end
true
end | [
"def",
"expect_view",
"(",
"query",
")",
"if",
"query",
".",
"nil?",
"raise",
"ArgumentError",
",",
"'Query cannot be nil'",
"end",
"unless",
"view_exists?",
"(",
"query",
")",
"raise",
"ViewNotFoundError",
",",
"\"No view matched #{Wait.parse_query_list(query)}\"",
"end",
"true",
"end"
]
| Expect `query` to match at least one view. Raise an exception if it does
not.
@param [String, Hash, Calabash::Query] query Query to match a view
@raise [ArgumentError] If given an invalid `query`
@raise [ViewNotFoundError] If `query` does not match at least one view | [
"Expect",
"query",
"to",
"match",
"at",
"least",
"one",
"view",
".",
"Raise",
"an",
"exception",
"if",
"it",
"does",
"not",
"."
]
| fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745 | https://github.com/calabash/calabash/blob/fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745/lib/calabash/wait.rb#L346-L357 | train |
calabash/calabash | lib/calabash/wait.rb | Calabash.Wait.expect_views | def expect_views(*queries)
if queries.nil? || queries.any?(&:nil?)
raise ArgumentError, 'Query cannot be nil'
end
unless views_exist?(*queries)
raise ViewNotFoundError,
"Not all queries #{Wait.parse_query_list(queries)} matched a view"
end
true
end | ruby | def expect_views(*queries)
if queries.nil? || queries.any?(&:nil?)
raise ArgumentError, 'Query cannot be nil'
end
unless views_exist?(*queries)
raise ViewNotFoundError,
"Not all queries #{Wait.parse_query_list(queries)} matched a view"
end
true
end | [
"def",
"expect_views",
"(",
"*",
"queries",
")",
"if",
"queries",
".",
"nil?",
"||",
"queries",
".",
"any?",
"(",
"&",
":nil?",
")",
"raise",
"ArgumentError",
",",
"'Query cannot be nil'",
"end",
"unless",
"views_exist?",
"(",
"*",
"queries",
")",
"raise",
"ViewNotFoundError",
",",
"\"Not all queries #{Wait.parse_query_list(queries)} matched a view\"",
"end",
"true",
"end"
]
| Expect `queries` to each match at least one view. Raise an exception if
they do not.
@param [String, Hash, Calabash::Query] queries List of queries or a
query.
@raise [ArgumentError] If given an invalid list of queries
@raise [ViewNotFoundError] If `queries` do not all match at least one
view. | [
"Expect",
"queries",
"to",
"each",
"match",
"at",
"least",
"one",
"view",
".",
"Raise",
"an",
"exception",
"if",
"they",
"do",
"not",
"."
]
| fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745 | https://github.com/calabash/calabash/blob/fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745/lib/calabash/wait.rb#L369-L380 | train |
calabash/calabash | lib/calabash/wait.rb | Calabash.Wait.do_not_expect_view | def do_not_expect_view(query)
if query.nil?
raise ArgumentError, 'Query cannot be nil'
end
if view_exists?(query)
raise ViewFoundError, "A view matched #{Wait.parse_query_list(query)}"
end
true
end | ruby | def do_not_expect_view(query)
if query.nil?
raise ArgumentError, 'Query cannot be nil'
end
if view_exists?(query)
raise ViewFoundError, "A view matched #{Wait.parse_query_list(query)}"
end
true
end | [
"def",
"do_not_expect_view",
"(",
"query",
")",
"if",
"query",
".",
"nil?",
"raise",
"ArgumentError",
",",
"'Query cannot be nil'",
"end",
"if",
"view_exists?",
"(",
"query",
")",
"raise",
"ViewFoundError",
",",
"\"A view matched #{Wait.parse_query_list(query)}\"",
"end",
"true",
"end"
]
| Expect `query` to match no views. Raise an exception if it does.
@param [String, Hash, Calabash::Query] query Query to match a view
@raise [ArgumentError] If given an invalid `query`
@raise [ViewFoundError] If `query` matches any views. | [
"Expect",
"query",
"to",
"match",
"no",
"views",
".",
"Raise",
"an",
"exception",
"if",
"it",
"does",
"."
]
| fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745 | https://github.com/calabash/calabash/blob/fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745/lib/calabash/wait.rb#L389-L399 | train |
calabash/calabash | lib/calabash/wait.rb | Calabash.Wait.do_not_expect_views | def do_not_expect_views(*queries)
if queries.nil? || queries.any?(&:nil?)
raise ArgumentError, 'Query cannot be nil'
end
if queries.map{|query| view_exists?(query)}.any?
raise ViewFoundError,
"Some views matched #{Wait.parse_query_list(queries)}"
end
true
end | ruby | def do_not_expect_views(*queries)
if queries.nil? || queries.any?(&:nil?)
raise ArgumentError, 'Query cannot be nil'
end
if queries.map{|query| view_exists?(query)}.any?
raise ViewFoundError,
"Some views matched #{Wait.parse_query_list(queries)}"
end
true
end | [
"def",
"do_not_expect_views",
"(",
"*",
"queries",
")",
"if",
"queries",
".",
"nil?",
"||",
"queries",
".",
"any?",
"(",
"&",
":nil?",
")",
"raise",
"ArgumentError",
",",
"'Query cannot be nil'",
"end",
"if",
"queries",
".",
"map",
"{",
"|",
"query",
"|",
"view_exists?",
"(",
"query",
")",
"}",
".",
"any?",
"raise",
"ViewFoundError",
",",
"\"Some views matched #{Wait.parse_query_list(queries)}\"",
"end",
"true",
"end"
]
| Expect `queries` to each match no views. Raise an exception if they do.
@param [String, Hash, Calabash::Query] queries List of queries or a
query.
@raise [ArgumentError] If given an invalid list of queries
@raise [ViewFoundError] If one of `queries` matched any views | [
"Expect",
"queries",
"to",
"each",
"match",
"no",
"views",
".",
"Raise",
"an",
"exception",
"if",
"they",
"do",
"."
]
| fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745 | https://github.com/calabash/calabash/blob/fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745/lib/calabash/wait.rb#L409-L420 | train |
calabash/calabash | lib/calabash/wait.rb | Calabash.Wait.wait_for_text | def wait_for_text(text,
timeout: Calabash::Wait.default_options[:timeout],
timeout_message: nil,
retry_frequency: Calabash::Wait.default_options[:retry_frequency])
wait_for_view("* {text CONTAINS[c] '#{text}'}",
timeout: timeout,
timeout_message: timeout_message,
retry_frequency: retry_frequency)
end | ruby | def wait_for_text(text,
timeout: Calabash::Wait.default_options[:timeout],
timeout_message: nil,
retry_frequency: Calabash::Wait.default_options[:retry_frequency])
wait_for_view("* {text CONTAINS[c] '#{text}'}",
timeout: timeout,
timeout_message: timeout_message,
retry_frequency: retry_frequency)
end | [
"def",
"wait_for_text",
"(",
"text",
",",
"timeout",
":",
"Calabash",
"::",
"Wait",
".",
"default_options",
"[",
":timeout",
"]",
",",
"timeout_message",
":",
"nil",
",",
"retry_frequency",
":",
"Calabash",
"::",
"Wait",
".",
"default_options",
"[",
":retry_frequency",
"]",
")",
"wait_for_view",
"(",
"\"* {text CONTAINS[c] '#{text}'}\"",
",",
"timeout",
":",
"timeout",
",",
"timeout_message",
":",
"timeout_message",
",",
"retry_frequency",
":",
"retry_frequency",
")",
"end"
]
| Waits for a view containing `text`.
@see Calabash::Wait#wait_for_view
@param text [String] Text to look for
@return [Object] The view matched by the text query | [
"Waits",
"for",
"a",
"view",
"containing",
"text",
"."
]
| fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745 | https://github.com/calabash/calabash/blob/fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745/lib/calabash/wait.rb#L430-L439 | train |
calabash/calabash | lib/calabash/wait.rb | Calabash.Wait.wait_for_no_text | def wait_for_no_text(text,
timeout: Calabash::Wait.default_options[:timeout],
timeout_message: nil,
retry_frequency: Calabash::Wait.default_options[:retry_frequency])
wait_for_no_view("* {text CONTAINS[c] '#{text}'}",
timeout: timeout,
timeout_message: timeout_message,
retry_frequency: retry_frequency)
end | ruby | def wait_for_no_text(text,
timeout: Calabash::Wait.default_options[:timeout],
timeout_message: nil,
retry_frequency: Calabash::Wait.default_options[:retry_frequency])
wait_for_no_view("* {text CONTAINS[c] '#{text}'}",
timeout: timeout,
timeout_message: timeout_message,
retry_frequency: retry_frequency)
end | [
"def",
"wait_for_no_text",
"(",
"text",
",",
"timeout",
":",
"Calabash",
"::",
"Wait",
".",
"default_options",
"[",
":timeout",
"]",
",",
"timeout_message",
":",
"nil",
",",
"retry_frequency",
":",
"Calabash",
"::",
"Wait",
".",
"default_options",
"[",
":retry_frequency",
"]",
")",
"wait_for_no_view",
"(",
"\"* {text CONTAINS[c] '#{text}'}\"",
",",
"timeout",
":",
"timeout",
",",
"timeout_message",
":",
"timeout_message",
",",
"retry_frequency",
":",
"retry_frequency",
")",
"end"
]
| Waits for no views containing `text`.
@see Calabash::Wait#wait_for_view
@param text [String] Text to look for
@return [Object] The view matched by the text query | [
"Waits",
"for",
"no",
"views",
"containing",
"text",
"."
]
| fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745 | https://github.com/calabash/calabash/blob/fac1ce9fcff6e2460c6e72a9b89d93a91a1bc745/lib/calabash/wait.rb#L447-L456 | train |
dicom/ruby-dicom | lib/dicom/audit_trail.rb | DICOM.AuditTrail.add_record | def add_record(tag, original, replacement)
@dictionary[tag] = Hash.new unless @dictionary.key?(tag)
@dictionary[tag][original] = replacement
end | ruby | def add_record(tag, original, replacement)
@dictionary[tag] = Hash.new unless @dictionary.key?(tag)
@dictionary[tag][original] = replacement
end | [
"def",
"add_record",
"(",
"tag",
",",
"original",
",",
"replacement",
")",
"@dictionary",
"[",
"tag",
"]",
"=",
"Hash",
".",
"new",
"unless",
"@dictionary",
".",
"key?",
"(",
"tag",
")",
"@dictionary",
"[",
"tag",
"]",
"[",
"original",
"]",
"=",
"replacement",
"end"
]
| Creates a new AuditTrail instance.
Adds a tag record to the log.
@param [String] tag the tag string (e.q. '0010,0010')
@param [String, Integer, Float] original the original value (e.q. 'John Doe')
@param [String, Integer, Float] replacement the replacement value (e.q. 'Patient1') | [
"Creates",
"a",
"new",
"AuditTrail",
"instance",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/audit_trail.rb#L41-L44 | train |
dicom/ruby-dicom | lib/dicom/audit_trail.rb | DICOM.AuditTrail.original | def original(tag, replacement)
original = nil
if @dictionary.key?(tag)
original = @dictionary[tag].key(replacement)
end
return original
end | ruby | def original(tag, replacement)
original = nil
if @dictionary.key?(tag)
original = @dictionary[tag].key(replacement)
end
return original
end | [
"def",
"original",
"(",
"tag",
",",
"replacement",
")",
"original",
"=",
"nil",
"if",
"@dictionary",
".",
"key?",
"(",
"tag",
")",
"original",
"=",
"@dictionary",
"[",
"tag",
"]",
".",
"key",
"(",
"replacement",
")",
"end",
"return",
"original",
"end"
]
| Retrieves the original value used for the given combination of tag & replacement value.
@param [String] tag the tag string (e.q. '0010,0010')
@param [String, Integer, Float] replacement the replacement value (e.q. 'Patient1')
@return [String, Integer, Float] the original value of the given tag | [
"Retrieves",
"the",
"original",
"value",
"used",
"for",
"the",
"given",
"combination",
"of",
"tag",
"&",
"replacement",
"value",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/audit_trail.rb#L60-L66 | train |
dicom/ruby-dicom | lib/dicom/audit_trail.rb | DICOM.AuditTrail.replacement | def replacement(tag, original)
replacement = nil
replacement = @dictionary[tag][original] if @dictionary.key?(tag)
return replacement
end | ruby | def replacement(tag, original)
replacement = nil
replacement = @dictionary[tag][original] if @dictionary.key?(tag)
return replacement
end | [
"def",
"replacement",
"(",
"tag",
",",
"original",
")",
"replacement",
"=",
"nil",
"replacement",
"=",
"@dictionary",
"[",
"tag",
"]",
"[",
"original",
"]",
"if",
"@dictionary",
".",
"key?",
"(",
"tag",
")",
"return",
"replacement",
"end"
]
| Retrieves the replacement value used for the given combination of tag & original value.
@param [String] tag the tag string (e.q. '0010,0010')
@param [String, Integer, Float] original the original value (e.q. 'John Doe')
@return [String, Integer, Float] the replacement value of the given tag | [
"Retrieves",
"the",
"replacement",
"value",
"used",
"for",
"the",
"given",
"combination",
"of",
"tag",
"&",
"original",
"value",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/audit_trail.rb#L87-L91 | train |
dicom/ruby-dicom | lib/dicom/d_object.rb | DICOM.DObject.encode_segments | def encode_segments(max_size, transfer_syntax=IMPLICIT_LITTLE_ENDIAN)
raise ArgumentError, "Invalid argument. Expected an Integer, got #{max_size.class}." unless max_size.is_a?(Integer)
raise ArgumentError, "Argument too low (#{max_size}), please specify a bigger Integer." unless max_size > 16
raise "Can not encode binary segments for an empty DICOM object." if children.length == 0
encode_in_segments(max_size, :syntax => transfer_syntax)
end | ruby | def encode_segments(max_size, transfer_syntax=IMPLICIT_LITTLE_ENDIAN)
raise ArgumentError, "Invalid argument. Expected an Integer, got #{max_size.class}." unless max_size.is_a?(Integer)
raise ArgumentError, "Argument too low (#{max_size}), please specify a bigger Integer." unless max_size > 16
raise "Can not encode binary segments for an empty DICOM object." if children.length == 0
encode_in_segments(max_size, :syntax => transfer_syntax)
end | [
"def",
"encode_segments",
"(",
"max_size",
",",
"transfer_syntax",
"=",
"IMPLICIT_LITTLE_ENDIAN",
")",
"raise",
"ArgumentError",
",",
"\"Invalid argument. Expected an Integer, got #{max_size.class}.\"",
"unless",
"max_size",
".",
"is_a?",
"(",
"Integer",
")",
"raise",
"ArgumentError",
",",
"\"Argument too low (#{max_size}), please specify a bigger Integer.\"",
"unless",
"max_size",
">",
"16",
"raise",
"\"Can not encode binary segments for an empty DICOM object.\"",
"if",
"children",
".",
"length",
"==",
"0",
"encode_in_segments",
"(",
"max_size",
",",
":syntax",
"=>",
"transfer_syntax",
")",
"end"
]
| Encodes the DICOM object into a series of binary string segments with a specified maximum length.
Returns the encoded binary strings in an array.
@param [Integer] max_size the maximum allowed size of the binary data strings to be encoded
@param [String] transfer_syntax the transfer syntax string to be used when encoding the DICOM object to string segments. When this method is used for making network packets, the transfer_syntax is not part of the object, and thus needs to be specified.
@return [Array<String>] the encoded DICOM strings
@example Encode the DObject to strings of max length 2^14 bytes
encoded_strings = dcm.encode_segments(16384) | [
"Encodes",
"the",
"DICOM",
"object",
"into",
"a",
"series",
"of",
"binary",
"string",
"segments",
"with",
"a",
"specified",
"maximum",
"length",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/d_object.rb#L230-L235 | train |
dicom/ruby-dicom | lib/dicom/d_object.rb | DICOM.DObject.summary | def summary
# FIXME: Perhaps this method should be split up in one or two separate methods
# which just builds the information arrays, and a third method for printing this to the screen.
sys_info = Array.new
info = Array.new
# Version of Ruby DICOM used:
sys_info << "Ruby DICOM version: #{VERSION}"
# System endian:
cpu = (CPU_ENDIAN ? "Big Endian" : "Little Endian")
sys_info << "Byte Order (CPU): #{cpu}"
# Source (file name):
if @source
if @source == :str
source = "Binary string #{@read_success ? '(successfully parsed)' : '(failed to parse)'}"
else
source = "File #{@read_success ? '(successfully read)' : '(failed to read)'}: #{@source}"
end
else
source = 'Created from scratch'
end
info << "Source: #{source}"
# Modality:
modality = (LIBRARY.uid(value('0008,0016')) ? LIBRARY.uid(value('0008,0016')).name : "SOP Class unknown or not specified!")
info << "Modality: #{modality}"
# Meta header presence (Simply check for the presence of the transfer syntax data element), VR and byte order:
ts_status = self['0002,0010'] ? '' : ' (Assumed)'
ts = LIBRARY.uid(transfer_syntax)
explicit = ts ? ts.explicit? : true
endian = ts ? ts.big_endian? : false
meta_comment = ts ? "" : " (But unknown/invalid transfer syntax: #{transfer_syntax})"
info << "Meta Header: #{self['0002,0010'] ? 'Yes' : 'No'}#{meta_comment}"
info << "Value Representation: #{explicit ? 'Explicit' : 'Implicit'}#{ts_status}"
info << "Byte Order (File): #{endian ? 'Big Endian' : 'Little Endian'}#{ts_status}"
# Pixel data:
pixels = self[PIXEL_TAG]
unless pixels
info << "Pixel Data: No"
else
info << "Pixel Data: Yes"
# Image size:
cols = (exists?("0028,0011") ? self["0028,0011"].value : "Columns missing")
rows = (exists?("0028,0010") ? self["0028,0010"].value : "Rows missing")
info << "Image Size: #{cols}*#{rows}"
# Frames:
frames = value("0028,0008") || "1"
unless frames == "1" or frames == 1
# Encapsulated or 3D pixel data:
if pixels.is_a?(Element)
frames = frames.to_s + " (3D Pixel Data)"
else
frames = frames.to_s + " (Encapsulated Multiframe Image)"
end
end
info << "Number of frames: #{frames}"
# Color:
colors = (exists?("0028,0004") ? self["0028,0004"].value : "Not specified")
info << "Photometry: #{colors}"
# Compression:
compression = (ts ? (ts.compressed_pixels? ? ts.name : 'No') : 'No' )
info << "Compression: #{compression}#{ts_status}"
# Pixel bits (allocated):
bits = (exists?("0028,0100") ? self["0028,0100"].value : "Not specified")
info << "Bits per Pixel: #{bits}"
end
# Print the DICOM object's key properties:
separator = "-------------------------------------------"
puts "System Properties:"
puts separator + "\n"
puts sys_info
puts "\n"
puts "DICOM Object Properties:"
puts separator
puts info
puts separator
return info
end | ruby | def summary
# FIXME: Perhaps this method should be split up in one or two separate methods
# which just builds the information arrays, and a third method for printing this to the screen.
sys_info = Array.new
info = Array.new
# Version of Ruby DICOM used:
sys_info << "Ruby DICOM version: #{VERSION}"
# System endian:
cpu = (CPU_ENDIAN ? "Big Endian" : "Little Endian")
sys_info << "Byte Order (CPU): #{cpu}"
# Source (file name):
if @source
if @source == :str
source = "Binary string #{@read_success ? '(successfully parsed)' : '(failed to parse)'}"
else
source = "File #{@read_success ? '(successfully read)' : '(failed to read)'}: #{@source}"
end
else
source = 'Created from scratch'
end
info << "Source: #{source}"
# Modality:
modality = (LIBRARY.uid(value('0008,0016')) ? LIBRARY.uid(value('0008,0016')).name : "SOP Class unknown or not specified!")
info << "Modality: #{modality}"
# Meta header presence (Simply check for the presence of the transfer syntax data element), VR and byte order:
ts_status = self['0002,0010'] ? '' : ' (Assumed)'
ts = LIBRARY.uid(transfer_syntax)
explicit = ts ? ts.explicit? : true
endian = ts ? ts.big_endian? : false
meta_comment = ts ? "" : " (But unknown/invalid transfer syntax: #{transfer_syntax})"
info << "Meta Header: #{self['0002,0010'] ? 'Yes' : 'No'}#{meta_comment}"
info << "Value Representation: #{explicit ? 'Explicit' : 'Implicit'}#{ts_status}"
info << "Byte Order (File): #{endian ? 'Big Endian' : 'Little Endian'}#{ts_status}"
# Pixel data:
pixels = self[PIXEL_TAG]
unless pixels
info << "Pixel Data: No"
else
info << "Pixel Data: Yes"
# Image size:
cols = (exists?("0028,0011") ? self["0028,0011"].value : "Columns missing")
rows = (exists?("0028,0010") ? self["0028,0010"].value : "Rows missing")
info << "Image Size: #{cols}*#{rows}"
# Frames:
frames = value("0028,0008") || "1"
unless frames == "1" or frames == 1
# Encapsulated or 3D pixel data:
if pixels.is_a?(Element)
frames = frames.to_s + " (3D Pixel Data)"
else
frames = frames.to_s + " (Encapsulated Multiframe Image)"
end
end
info << "Number of frames: #{frames}"
# Color:
colors = (exists?("0028,0004") ? self["0028,0004"].value : "Not specified")
info << "Photometry: #{colors}"
# Compression:
compression = (ts ? (ts.compressed_pixels? ? ts.name : 'No') : 'No' )
info << "Compression: #{compression}#{ts_status}"
# Pixel bits (allocated):
bits = (exists?("0028,0100") ? self["0028,0100"].value : "Not specified")
info << "Bits per Pixel: #{bits}"
end
# Print the DICOM object's key properties:
separator = "-------------------------------------------"
puts "System Properties:"
puts separator + "\n"
puts sys_info
puts "\n"
puts "DICOM Object Properties:"
puts separator
puts info
puts separator
return info
end | [
"def",
"summary",
"sys_info",
"=",
"Array",
".",
"new",
"info",
"=",
"Array",
".",
"new",
"sys_info",
"<<",
"\"Ruby DICOM version: #{VERSION}\"",
"cpu",
"=",
"(",
"CPU_ENDIAN",
"?",
"\"Big Endian\"",
":",
"\"Little Endian\"",
")",
"sys_info",
"<<",
"\"Byte Order (CPU): #{cpu}\"",
"if",
"@source",
"if",
"@source",
"==",
":str",
"source",
"=",
"\"Binary string #{@read_success ? '(successfully parsed)' : '(failed to parse)'}\"",
"else",
"source",
"=",
"\"File #{@read_success ? '(successfully read)' : '(failed to read)'}: #{@source}\"",
"end",
"else",
"source",
"=",
"'Created from scratch'",
"end",
"info",
"<<",
"\"Source: #{source}\"",
"modality",
"=",
"(",
"LIBRARY",
".",
"uid",
"(",
"value",
"(",
"'0008,0016'",
")",
")",
"?",
"LIBRARY",
".",
"uid",
"(",
"value",
"(",
"'0008,0016'",
")",
")",
".",
"name",
":",
"\"SOP Class unknown or not specified!\"",
")",
"info",
"<<",
"\"Modality: #{modality}\"",
"ts_status",
"=",
"self",
"[",
"'0002,0010'",
"]",
"?",
"''",
":",
"' (Assumed)'",
"ts",
"=",
"LIBRARY",
".",
"uid",
"(",
"transfer_syntax",
")",
"explicit",
"=",
"ts",
"?",
"ts",
".",
"explicit?",
":",
"true",
"endian",
"=",
"ts",
"?",
"ts",
".",
"big_endian?",
":",
"false",
"meta_comment",
"=",
"ts",
"?",
"\"\"",
":",
"\" (But unknown/invalid transfer syntax: #{transfer_syntax})\"",
"info",
"<<",
"\"Meta Header: #{self['0002,0010'] ? 'Yes' : 'No'}#{meta_comment}\"",
"info",
"<<",
"\"Value Representation: #{explicit ? 'Explicit' : 'Implicit'}#{ts_status}\"",
"info",
"<<",
"\"Byte Order (File): #{endian ? 'Big Endian' : 'Little Endian'}#{ts_status}\"",
"pixels",
"=",
"self",
"[",
"PIXEL_TAG",
"]",
"unless",
"pixels",
"info",
"<<",
"\"Pixel Data: No\"",
"else",
"info",
"<<",
"\"Pixel Data: Yes\"",
"cols",
"=",
"(",
"exists?",
"(",
"\"0028,0011\"",
")",
"?",
"self",
"[",
"\"0028,0011\"",
"]",
".",
"value",
":",
"\"Columns missing\"",
")",
"rows",
"=",
"(",
"exists?",
"(",
"\"0028,0010\"",
")",
"?",
"self",
"[",
"\"0028,0010\"",
"]",
".",
"value",
":",
"\"Rows missing\"",
")",
"info",
"<<",
"\"Image Size: #{cols}*#{rows}\"",
"frames",
"=",
"value",
"(",
"\"0028,0008\"",
")",
"||",
"\"1\"",
"unless",
"frames",
"==",
"\"1\"",
"or",
"frames",
"==",
"1",
"if",
"pixels",
".",
"is_a?",
"(",
"Element",
")",
"frames",
"=",
"frames",
".",
"to_s",
"+",
"\" (3D Pixel Data)\"",
"else",
"frames",
"=",
"frames",
".",
"to_s",
"+",
"\" (Encapsulated Multiframe Image)\"",
"end",
"end",
"info",
"<<",
"\"Number of frames: #{frames}\"",
"colors",
"=",
"(",
"exists?",
"(",
"\"0028,0004\"",
")",
"?",
"self",
"[",
"\"0028,0004\"",
"]",
".",
"value",
":",
"\"Not specified\"",
")",
"info",
"<<",
"\"Photometry: #{colors}\"",
"compression",
"=",
"(",
"ts",
"?",
"(",
"ts",
".",
"compressed_pixels?",
"?",
"ts",
".",
"name",
":",
"'No'",
")",
":",
"'No'",
")",
"info",
"<<",
"\"Compression: #{compression}#{ts_status}\"",
"bits",
"=",
"(",
"exists?",
"(",
"\"0028,0100\"",
")",
"?",
"self",
"[",
"\"0028,0100\"",
"]",
".",
"value",
":",
"\"Not specified\"",
")",
"info",
"<<",
"\"Bits per Pixel: #{bits}\"",
"end",
"separator",
"=",
"\"-------------------------------------------\"",
"puts",
"\"System Properties:\"",
"puts",
"separator",
"+",
"\"\\n\"",
"puts",
"sys_info",
"puts",
"\"\\n\"",
"puts",
"\"DICOM Object Properties:\"",
"puts",
"separator",
"puts",
"info",
"puts",
"separator",
"return",
"info",
"end"
]
| Gathers key information about the DObject as well as some system data, and prints this information to the screen.
This information includes properties like encoding, byte order, modality and various image properties.
@return [Array<String>] strings describing the properties of the DICOM object | [
"Gathers",
"key",
"information",
"about",
"the",
"DObject",
"as",
"well",
"as",
"some",
"system",
"data",
"and",
"prints",
"this",
"information",
"to",
"the",
"screen",
".",
"This",
"information",
"includes",
"properties",
"like",
"encoding",
"byte",
"order",
"modality",
"and",
"various",
"image",
"properties",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/d_object.rb#L261-L336 | train |
dicom/ruby-dicom | lib/dicom/d_object.rb | DICOM.DObject.transfer_syntax= | def transfer_syntax=(new_syntax)
# Verify old and new transfer syntax:
new_uid = LIBRARY.uid(new_syntax)
old_uid = LIBRARY.uid(transfer_syntax)
raise ArgumentError, "Invalid/unknown transfer syntax specified: #{new_syntax}" unless new_uid && new_uid.transfer_syntax?
raise ArgumentError, "Invalid/unknown existing transfer syntax: #{new_syntax} Unable to reliably handle byte order encoding. Modify the transfer syntax element directly instead." unless old_uid && old_uid.transfer_syntax?
# Set the new transfer syntax:
if exists?("0002,0010")
self["0002,0010"].value = new_syntax
else
add(Element.new("0002,0010", new_syntax))
end
# Update our Stream instance with the new encoding:
@stream.endian = new_uid.big_endian?
# If endianness is changed, re-encode elements (only elements depending on endianness will actually be re-encoded):
encode_children(old_uid.big_endian?) if old_uid.big_endian? != new_uid.big_endian?
end | ruby | def transfer_syntax=(new_syntax)
# Verify old and new transfer syntax:
new_uid = LIBRARY.uid(new_syntax)
old_uid = LIBRARY.uid(transfer_syntax)
raise ArgumentError, "Invalid/unknown transfer syntax specified: #{new_syntax}" unless new_uid && new_uid.transfer_syntax?
raise ArgumentError, "Invalid/unknown existing transfer syntax: #{new_syntax} Unable to reliably handle byte order encoding. Modify the transfer syntax element directly instead." unless old_uid && old_uid.transfer_syntax?
# Set the new transfer syntax:
if exists?("0002,0010")
self["0002,0010"].value = new_syntax
else
add(Element.new("0002,0010", new_syntax))
end
# Update our Stream instance with the new encoding:
@stream.endian = new_uid.big_endian?
# If endianness is changed, re-encode elements (only elements depending on endianness will actually be re-encoded):
encode_children(old_uid.big_endian?) if old_uid.big_endian? != new_uid.big_endian?
end | [
"def",
"transfer_syntax",
"=",
"(",
"new_syntax",
")",
"new_uid",
"=",
"LIBRARY",
".",
"uid",
"(",
"new_syntax",
")",
"old_uid",
"=",
"LIBRARY",
".",
"uid",
"(",
"transfer_syntax",
")",
"raise",
"ArgumentError",
",",
"\"Invalid/unknown transfer syntax specified: #{new_syntax}\"",
"unless",
"new_uid",
"&&",
"new_uid",
".",
"transfer_syntax?",
"raise",
"ArgumentError",
",",
"\"Invalid/unknown existing transfer syntax: #{new_syntax} Unable to reliably handle byte order encoding. Modify the transfer syntax element directly instead.\"",
"unless",
"old_uid",
"&&",
"old_uid",
".",
"transfer_syntax?",
"if",
"exists?",
"(",
"\"0002,0010\"",
")",
"self",
"[",
"\"0002,0010\"",
"]",
".",
"value",
"=",
"new_syntax",
"else",
"add",
"(",
"Element",
".",
"new",
"(",
"\"0002,0010\"",
",",
"new_syntax",
")",
")",
"end",
"@stream",
".",
"endian",
"=",
"new_uid",
".",
"big_endian?",
"encode_children",
"(",
"old_uid",
".",
"big_endian?",
")",
"if",
"old_uid",
".",
"big_endian?",
"!=",
"new_uid",
".",
"big_endian?",
"end"
]
| Changes the transfer syntax Element of the DObject instance, and performs re-encoding of all
numerical values if a switch of endianness is implied.
@note This method does not change the compressed state of the pixel data element. Changing
the transfer syntax between an uncompressed and compressed state will NOT change the pixel
data accordingly (this must be taken care of manually).
@param [String] new_syntax the new transfer syntax string to be applied to the DObject | [
"Changes",
"the",
"transfer",
"syntax",
"Element",
"of",
"the",
"DObject",
"instance",
"and",
"performs",
"re",
"-",
"encoding",
"of",
"all",
"numerical",
"values",
"if",
"a",
"switch",
"of",
"endianness",
"is",
"implied",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/d_object.rb#L365-L381 | train |
dicom/ruby-dicom | lib/dicom/d_object.rb | DICOM.DObject.write | def write(file_name, options={})
raise ArgumentError, "Invalid file_name. Expected String, got #{file_name.class}." unless file_name.is_a?(String)
@include_empty_parents = options[:include_empty_parents]
insert_missing_meta unless options[:ignore_meta]
write_elements(:file_name => file_name, :signature => true, :syntax => transfer_syntax)
end | ruby | def write(file_name, options={})
raise ArgumentError, "Invalid file_name. Expected String, got #{file_name.class}." unless file_name.is_a?(String)
@include_empty_parents = options[:include_empty_parents]
insert_missing_meta unless options[:ignore_meta]
write_elements(:file_name => file_name, :signature => true, :syntax => transfer_syntax)
end | [
"def",
"write",
"(",
"file_name",
",",
"options",
"=",
"{",
"}",
")",
"raise",
"ArgumentError",
",",
"\"Invalid file_name. Expected String, got #{file_name.class}.\"",
"unless",
"file_name",
".",
"is_a?",
"(",
"String",
")",
"@include_empty_parents",
"=",
"options",
"[",
":include_empty_parents",
"]",
"insert_missing_meta",
"unless",
"options",
"[",
":ignore_meta",
"]",
"write_elements",
"(",
":file_name",
"=>",
"file_name",
",",
":signature",
"=>",
"true",
",",
":syntax",
"=>",
"transfer_syntax",
")",
"end"
]
| Writes the DICOM object to file.
@note The goal of the Ruby DICOM library is to yield maximum conformance with the DICOM
standard when outputting DICOM files. Therefore, when encoding the DICOM file, manipulation
of items such as the meta group, group lengths and header signature may occur. Therefore,
the file that is written may not be an exact bitwise copy of the file that was read, even if no
DObject manipulation has been done by the user.
@param [String] file_name the path of the DICOM file which is to be written to disk
@param [Hash] options the options to use for writing the DICOM file
@option options [Boolean] :ignore_meta if true, no manipulation of the DICOM object's meta group will be performed before the DObject is written to file
@option options [Boolean] :include_empty_parents if true, childless parents (sequences & items) are written to the DICOM file
@example Encode a DICOM file from a DObject
dcm.write('C:/dicom/test.dcm') | [
"Writes",
"the",
"DICOM",
"object",
"to",
"file",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/d_object.rb#L398-L403 | train |
dicom/ruby-dicom | lib/dicom/d_object.rb | DICOM.DObject.meta_group_length | def meta_group_length
group_length = 0
meta_elements = group(META_GROUP)
tag = 4
vr = 2
meta_elements.each do |element|
case element.vr
when "OB","OW","OF","SQ","UN","UT"
length = 6
else
length = 2
end
group_length += tag + vr + length + element.bin.length
end
group_length
end | ruby | def meta_group_length
group_length = 0
meta_elements = group(META_GROUP)
tag = 4
vr = 2
meta_elements.each do |element|
case element.vr
when "OB","OW","OF","SQ","UN","UT"
length = 6
else
length = 2
end
group_length += tag + vr + length + element.bin.length
end
group_length
end | [
"def",
"meta_group_length",
"group_length",
"=",
"0",
"meta_elements",
"=",
"group",
"(",
"META_GROUP",
")",
"tag",
"=",
"4",
"vr",
"=",
"2",
"meta_elements",
".",
"each",
"do",
"|",
"element",
"|",
"case",
"element",
".",
"vr",
"when",
"\"OB\"",
",",
"\"OW\"",
",",
"\"OF\"",
",",
"\"SQ\"",
",",
"\"UN\"",
",",
"\"UT\"",
"length",
"=",
"6",
"else",
"length",
"=",
"2",
"end",
"group_length",
"+=",
"tag",
"+",
"vr",
"+",
"length",
"+",
"element",
".",
"bin",
".",
"length",
"end",
"group_length",
"end"
]
| Determines the length of the meta group in the DObject instance.
@return [Integer] the length of the file meta group string | [
"Determines",
"the",
"length",
"of",
"the",
"meta",
"group",
"in",
"the",
"DObject",
"instance",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/d_object.rb#L438-L453 | train |
dicom/ruby-dicom | lib/dicom/image_item.rb | DICOM.ImageItem.add_element | def add_element(tag, value, options={})
add(e = Element.new(tag, value, options))
e
end | ruby | def add_element(tag, value, options={})
add(e = Element.new(tag, value, options))
e
end | [
"def",
"add_element",
"(",
"tag",
",",
"value",
",",
"options",
"=",
"{",
"}",
")",
"add",
"(",
"e",
"=",
"Element",
".",
"new",
"(",
"tag",
",",
"value",
",",
"options",
")",
")",
"e",
"end"
]
| Creates an Element with the given arguments and connects it to self.
@param [String] tag an element tag
@param [String, Integer, Float, Array, NilClass] value an element value
@param [Hash] options any options used for creating the element (see Element.new documentation) | [
"Creates",
"an",
"Element",
"with",
"the",
"given",
"arguments",
"and",
"connects",
"it",
"to",
"self",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/image_item.rb#L23-L26 | train |
dicom/ruby-dicom | lib/dicom/image_item.rb | DICOM.ImageItem.add_sequence | def add_sequence(tag, options={})
add(s = Sequence.new(tag, options))
s
end | ruby | def add_sequence(tag, options={})
add(s = Sequence.new(tag, options))
s
end | [
"def",
"add_sequence",
"(",
"tag",
",",
"options",
"=",
"{",
"}",
")",
"add",
"(",
"s",
"=",
"Sequence",
".",
"new",
"(",
"tag",
",",
"options",
")",
")",
"s",
"end"
]
| Creates a Sequence with the given arguments and connects it to self.
@param [String] tag a sequence tag
@param [Hash] options any options used for creating the sequence (see Sequence.new documentation) | [
"Creates",
"a",
"Sequence",
"with",
"the",
"given",
"arguments",
"and",
"connects",
"it",
"to",
"self",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/image_item.rb#L33-L36 | train |
dicom/ruby-dicom | lib/dicom/image_item.rb | DICOM.ImageItem.color? | def color?
# "Photometric Interpretation" is contained in the data element "0028,0004":
begin
photometric = photometry
if photometric.include?('COLOR') or photometric.include?('RGB') or photometric.include?('YBR')
return true
else
return false
end
rescue
return false
end
end | ruby | def color?
# "Photometric Interpretation" is contained in the data element "0028,0004":
begin
photometric = photometry
if photometric.include?('COLOR') or photometric.include?('RGB') or photometric.include?('YBR')
return true
else
return false
end
rescue
return false
end
end | [
"def",
"color?",
"begin",
"photometric",
"=",
"photometry",
"if",
"photometric",
".",
"include?",
"(",
"'COLOR'",
")",
"or",
"photometric",
".",
"include?",
"(",
"'RGB'",
")",
"or",
"photometric",
".",
"include?",
"(",
"'YBR'",
")",
"return",
"true",
"else",
"return",
"false",
"end",
"rescue",
"return",
"false",
"end",
"end"
]
| Checks if colored pixel data is present.
@return [Boolean] true if the object contains colored pixels, and false if not | [
"Checks",
"if",
"colored",
"pixel",
"data",
"is",
"present",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/image_item.rb#L42-L54 | train |
dicom/ruby-dicom | lib/dicom/image_item.rb | DICOM.ImageItem.decode_pixels | def decode_pixels(bin, stream=@stream)
raise ArgumentError, "Expected String, got #{bin.class}." unless bin.is_a?(String)
pixels = false
# We need to know what kind of bith depth and integer type the pixel data is saved with:
bit_depth_element = self['0028,0100']
pixel_representation_element = self['0028,0103']
if bit_depth_element and pixel_representation_element
# Load the binary pixel data to the Stream instance:
stream.set_string(bin)
template = template_string(bit_depth_element.value.to_i)
pixels = stream.decode_all(template) if template
else
raise "The Element specifying Bit Depth (0028,0100) is missing. Unable to decode pixel data." unless bit_depth_element
raise "The Element specifying Pixel Representation (0028,0103) is missing. Unable to decode pixel data." unless pixel_representation_element
end
return pixels
end | ruby | def decode_pixels(bin, stream=@stream)
raise ArgumentError, "Expected String, got #{bin.class}." unless bin.is_a?(String)
pixels = false
# We need to know what kind of bith depth and integer type the pixel data is saved with:
bit_depth_element = self['0028,0100']
pixel_representation_element = self['0028,0103']
if bit_depth_element and pixel_representation_element
# Load the binary pixel data to the Stream instance:
stream.set_string(bin)
template = template_string(bit_depth_element.value.to_i)
pixels = stream.decode_all(template) if template
else
raise "The Element specifying Bit Depth (0028,0100) is missing. Unable to decode pixel data." unless bit_depth_element
raise "The Element specifying Pixel Representation (0028,0103) is missing. Unable to decode pixel data." unless pixel_representation_element
end
return pixels
end | [
"def",
"decode_pixels",
"(",
"bin",
",",
"stream",
"=",
"@stream",
")",
"raise",
"ArgumentError",
",",
"\"Expected String, got #{bin.class}.\"",
"unless",
"bin",
".",
"is_a?",
"(",
"String",
")",
"pixels",
"=",
"false",
"bit_depth_element",
"=",
"self",
"[",
"'0028,0100'",
"]",
"pixel_representation_element",
"=",
"self",
"[",
"'0028,0103'",
"]",
"if",
"bit_depth_element",
"and",
"pixel_representation_element",
"stream",
".",
"set_string",
"(",
"bin",
")",
"template",
"=",
"template_string",
"(",
"bit_depth_element",
".",
"value",
".",
"to_i",
")",
"pixels",
"=",
"stream",
".",
"decode_all",
"(",
"template",
")",
"if",
"template",
"else",
"raise",
"\"The Element specifying Bit Depth (0028,0100) is missing. Unable to decode pixel data.\"",
"unless",
"bit_depth_element",
"raise",
"\"The Element specifying Pixel Representation (0028,0103) is missing. Unable to decode pixel data.\"",
"unless",
"pixel_representation_element",
"end",
"return",
"pixels",
"end"
]
| Unpacks pixel values from a binary pixel string. The decode is performed
using values defined in the image related elements of the DObject instance.
@param [String] bin a binary string containing the pixels to be decoded
@param [Stream] stream a Stream instance to be used for decoding the pixels (optional)
@return [Array<Integer>] decoded pixel values | [
"Unpacks",
"pixel",
"values",
"from",
"a",
"binary",
"pixel",
"string",
".",
"The",
"decode",
"is",
"performed",
"using",
"values",
"defined",
"in",
"the",
"image",
"related",
"elements",
"of",
"the",
"DObject",
"instance",
"."
]
| 3ffcfe21edc8dcd31298f945781990789fc832ab | https://github.com/dicom/ruby-dicom/blob/3ffcfe21edc8dcd31298f945781990789fc832ab/lib/dicom/image_item.rb#L76-L92 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.