Dicom_UID 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dicom_uid.rb +29 -10
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48794268290e7c2a88d4c2be888492ae8b32b62ed73500ed51a0653ae9b0cc60
|
4
|
+
data.tar.gz: 7eb0fc128363463b48bd4f799c2a3a9487ad9857b748667a10982d792e48e8fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e63b07e2e8274fca43ee4b4587952c194f3690cdc0435008d7f2ea23f44036dd742acb3b4f41e73a0b95b9dbfc139d93289181beea8112db3f35e5bcc6fb0a8
|
7
|
+
data.tar.gz: 769293cc95e8789e09d725465c3e531940a3c1ef6cc969b621816bc92ac236528487e9eeff2b6ef4758986b1d337a296b834ba88a963bc3fb8804b7887388c38
|
data/lib/dicom_uid.rb
CHANGED
@@ -5,20 +5,33 @@
|
|
5
5
|
# <org>.<suffix>
|
6
6
|
class DicomUID
|
7
7
|
|
8
|
+
attr_accessor :uid, :name
|
9
|
+
|
10
|
+
def initialize name
|
11
|
+
@uid = random_dicom_uid '', nil
|
12
|
+
@name = name
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_s
|
16
|
+
'UID : ' << @uid << ' NAME : ' << @name
|
17
|
+
end
|
18
|
+
|
8
19
|
|
9
20
|
# Generates random component with random, defined, length
|
10
|
-
def
|
21
|
+
def random_component length = 64, odd_byte_boundary
|
22
|
+
|
11
23
|
# randing length of number
|
12
24
|
length_component = length - 1
|
13
25
|
loop do
|
14
|
-
|
15
|
-
|
16
|
-
|
26
|
+
srand
|
27
|
+
length_component = rand(0..length)
|
28
|
+
break if length_component != length - 1 and length_component != 0
|
17
29
|
end
|
18
30
|
|
19
31
|
# randing the component
|
20
32
|
component = (rand ('9' * length_component).to_i).to_s
|
21
|
-
|
33
|
+
|
34
|
+
if odd_byte_boundary and component[-1].to_i % 2 == 1# if odd number
|
22
35
|
component << 'O'
|
23
36
|
component = component[1..-1]# removing first int
|
24
37
|
end
|
@@ -28,7 +41,7 @@ class DicomUID
|
|
28
41
|
|
29
42
|
|
30
43
|
# Generate recursively a random dicom uid
|
31
|
-
def
|
44
|
+
def rand_duid uid = '', remain
|
32
45
|
comp = self.random_component remain
|
33
46
|
remain -= comp.length
|
34
47
|
uid << comp
|
@@ -42,16 +55,22 @@ class DicomUID
|
|
42
55
|
|
43
56
|
# set default values, with org_root if needed
|
44
57
|
# the size of the UID is randomized
|
45
|
-
def
|
58
|
+
def random_dicom_uid org_root, fixed_size, odd_byte_boundary = true
|
59
|
+
|
46
60
|
# building the org root
|
47
61
|
org_root ||= random_component# UID needs at least an org root
|
48
62
|
raise LeadingZeroError if org_root[0] == '0' and org_root.length != 1
|
49
|
-
raise OddByteError if org_root[-2].to_i % 2 == 1 and org_root[-1] != 0
|
63
|
+
raise OddByteError if org_root[-2].to_i % 2 == 1 and org_root[-1] != 0 and odd_byte_boundary
|
50
64
|
org_root << '.' if org_root[-1] != '.'
|
65
|
+
|
51
66
|
srand
|
52
67
|
fixed_size ||= rand 64
|
68
|
+
|
69
|
+
raise OversizedUIDError if fixed_size > 64
|
70
|
+
raise RangeError("Size of UID can't be negative") if fixed_size < 0
|
71
|
+
|
53
72
|
# building the suffix
|
54
|
-
|
73
|
+
self.rand_duid org_root, (fixed_size - org_root.length), odd_byte_boundary
|
55
74
|
end
|
56
75
|
|
57
76
|
end
|
@@ -74,4 +93,4 @@ class OversizedUIDError < StandardError
|
|
74
93
|
def initialize msg = "UID musn't be more than 64 characters"
|
75
94
|
super
|
76
95
|
end
|
77
|
-
end
|
96
|
+
end
|