Dicom_UID 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/dicom_uid.rb +29 -10
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 77add1d490996873947cbb9b63cb9ac6731b9107362da19707bb6c6918d0f65d
4
- data.tar.gz: aa93e16d1ea8374321ccdb4b0f3b772d768af63cd80c0ac8a39ac04c7a583d0a
3
+ metadata.gz: 48794268290e7c2a88d4c2be888492ae8b32b62ed73500ed51a0653ae9b0cc60
4
+ data.tar.gz: 7eb0fc128363463b48bd4f799c2a3a9487ad9857b748667a10982d792e48e8fe
5
5
  SHA512:
6
- metadata.gz: 2d2f8ff395c4867c134176b99a4970a740769a1e802e291366d98a819d28ef59300e3be05947631fc355b016e835c2de08d857402444fa4f8095517eb90a345e
7
- data.tar.gz: 23eab413d47fd50ad28a8bc7768f3c1bc8b3163fb69b4a6e93e3c99dffeccab55e3a3ebc3517a7166ab483fb37fe35031ba00a5e7a76e1772f8402f85418bb38
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 self.random_component length = 64
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
- srand
15
- length_component = rand(0..length)
16
- break if length_component != length - 1 and length_component != 0
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
- if component[-1].to_i % 2 == 1# if odd number
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 self.rand_duid uid = '', remain
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 self.random_dicom_uid org_root, fixed_size
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
- return self.rand_duid org_root, (fixed_size - org_root.length)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Dicom_UID
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Repain Paul