Dicom_UID 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/dicom_uid.rb +32 -3
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2598742649426f416a4829dddc2e383492f65a37eabfbe8f38936420eae981ee
4
- data.tar.gz: 91af01a8d1ae77d0c6c2ecf206dc94ba10e68d78e80780fb3a621b49e2ea9e96
3
+ metadata.gz: 77add1d490996873947cbb9b63cb9ac6731b9107362da19707bb6c6918d0f65d
4
+ data.tar.gz: aa93e16d1ea8374321ccdb4b0f3b772d768af63cd80c0ac8a39ac04c7a583d0a
5
5
  SHA512:
6
- metadata.gz: a9a3bcba499f0ff002926d06766584cab15dd100be2a5f6c8e7e1075ae53cf5afdc5581e89429045b5e43113e114dc2d90f904fe7746c0063bcb6795ee2053e6
7
- data.tar.gz: 4334079996de6849f8821f7e4f74f313004963f8a62080451a0901a81aab062698619ed18c893359305503d88fc43aba2a81aef67f358d85f1b312f469491e72
6
+ metadata.gz: 2d2f8ff395c4867c134176b99a4970a740769a1e802e291366d98a819d28ef59300e3be05947631fc355b016e835c2de08d857402444fa4f8095517eb90a345e
7
+ data.tar.gz: 23eab413d47fd50ad28a8bc7768f3c1bc8b3163fb69b4a6e93e3c99dffeccab55e3a3ebc3517a7166ab483fb37fe35031ba00a5e7a76e1772f8402f85418bb38
data/lib/dicom_uid.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  # DICOM UID Generator according to the DICOM documentation
4
4
  # http://dicom.nema.org/dicom/2013/output/chtml/part05/chapter_9.html
5
+ # <org>.<suffix>
5
6
  class DicomUID
6
7
 
7
8
 
@@ -40,9 +41,37 @@ class DicomUID
40
41
 
41
42
 
42
43
  # set default values, with org_root if needed
43
- def self.random_dicom_uid org_root = '', size = 64
44
- org_root << '.' if !org_root.empty? and org_root[-1] != '.'
45
- return self.rand_duid org_root, size
44
+ # the size of the UID is randomized
45
+ def self.random_dicom_uid org_root, fixed_size
46
+ # building the org root
47
+ org_root ||= random_component# UID needs at least an org root
48
+ 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
50
+ org_root << '.' if org_root[-1] != '.'
51
+ srand
52
+ fixed_size ||= rand 64
53
+ # building the suffix
54
+ return self.rand_duid org_root, (fixed_size - org_root.length)
46
55
  end
47
56
 
48
57
  end
58
+
59
+ # EXCEPTIONS
60
+
61
+ class LeadingZeroError < StandardError
62
+ def initialize msg = "Can't have a leading 0 in a component with multiple digits"
63
+ super
64
+ end
65
+ end
66
+
67
+ class OddByteError < StandardError
68
+ def initialize msg = "Can't have an odd last byte in a component"
69
+ super
70
+ end
71
+ end
72
+
73
+ class OversizedUIDError < StandardError
74
+ def initialize msg = "UID musn't be more than 64 characters"
75
+ super
76
+ end
77
+ 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.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Repain Paul