Dicom_UID 0.0.13 → 0.0.15

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 (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +15 -2
  3. data/lib/dicom_uid.rb +26 -44
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 87ce3cded18e449b8bf2e4b748f76da5ac13716f8a4765434034dcf4f0567155
4
- data.tar.gz: a5a2476d25443b8071eecea0c76a3ceea798b48f6aff392c363f74b59741a2cd
3
+ metadata.gz: 93f2b64dd2594ac1122cc624b35597a2a18af269a26023d6bff74aeedca605cd
4
+ data.tar.gz: dc0f37dccf407397d7476692289ded0e0658313e93e8e0d07a90640e3f810ebb
5
5
  SHA512:
6
- metadata.gz: f93a96fe9362387bdb8af185153b9c355f164c1494d3de8fa63ff2f8266db29476af0396a285de8e933a356ff3280d43c980c91ece41edbe6b5796499a9e7f32
7
- data.tar.gz: 8c040e45b46f6d7c3124c215b5b1ec2c6dcb6035cc61ea2b3a7a90f3f417423a8cfb1ec7067a9db6725b94c026dcf104d6207755396064dde4f91b339d6aa036
6
+ metadata.gz: 5d34818eefeb7579057055c4c0d457692895ff6caa4c4ba0ac9af2e33ff54d09e5bea2789525026ef1f12600aeb3c07100554fc78776cbc10faab590ab7a49ce
7
+ data.tar.gz: bcf8b9e9d594bd46aa70dc54a4898ad506f9a17ebaf009584144a6c8a91363c23217042a0a006be29440519da138f9ba83cabf0310732686666ebed8e35bbc04
data/README.md CHANGED
@@ -2,10 +2,23 @@
2
2
 
3
3
  Gem generating DICOM random UID
4
4
 
5
+
6
+ ## Documentation
7
+
8
+ ![Here](https://poulpy.github.io/DICOM-UID/docs/)
9
+
10
+
5
11
  ## Examples
6
12
 
7
13
  ```ruby
8
- DicomUID.random_dicom_uid '10.12.6.64', 60
9
- DicomUID.random_dicom_uid '1.1.3.62', 30, false
14
+ DicomUID.random_dicom_uid '10.12.6.64', 60
15
+ # 10.12.6.64.427667812798425850151433034003527467011730.452.0
16
+ DicomUID.random_dicom_uid '1.1.3.62', 30, false
17
+ # 1.1.3.62.5029609471.336514265
18
+
19
+ DicomUID.random_component 6
20
+ # 9538
21
+ DicomUID.random_component 30, false
22
+ # 59452307
10
23
  ```
11
24
 
@@ -6,9 +6,32 @@
6
6
  # The UID must not be more than 64 characters, dots included.
7
7
  module DicomUID
8
8
 
9
- # Maximum size of an UID
10
- MAXIMUM_SIZE = 64
9
+ # set default values, with org_root if needed
10
+ # the size of the UID is randomized
11
+ # fixed_size is the size ogf the whole UID, with the org taken into account
12
+ def self.random_dicom_uid org_root, fixed_size, odd_byte_boundary = true
13
+
14
+ raise TypeError, 'Org root must be a string or an Integer' unless org_root.is_a? String or org_root.is_a? Integer
15
+ org_root = org_root.to_s if org_root.is_a? Integer
16
+ raise TypeError unless fixed_size.is_a? Integer and odd_byte_boundary == !!odd_byte_boundary
17
+
18
+ # building the org root
19
+ org_root = self.random_component(62, odd_byte_boundary) if org_root.empty?# UID needs at least an org root
20
+ raise LeadingZeroError if leading_zero? org_root
21
+ raise OddByteError if !odd_byte_rule(org_root) and odd_byte_boundary
22
+
23
+ # if the fixed size doesn't exist, a random one is created, but
24
+ # it must be generated so that the UID musn't be above 64 chars
25
+ fixed_size ||= rand(0..(64 - org_root.length - 1))
26
+ fixed_size -= 1 if add_missing_dot org_root
11
27
 
28
+ raise OversizedUIDError if fixed_size > 64
29
+ raise RangeError, 'Size of Org root larger than size provided' if fixed_size < org_root.length
30
+ raise RangeError, "Size of UID can't be negative" if fixed_size < 0
31
+
32
+ # building the suffix
33
+ self.rand_duid org_root, (fixed_size - org_root.length), odd_byte_boundary
34
+ end
12
35
 
13
36
  # Generates random component with defined, maximum length
14
37
  # The maximum length is 62. Why ? Because an UID has at least an org_root
@@ -44,38 +67,6 @@ module DicomUID
44
67
  component
45
68
  end
46
69
 
47
-
48
-
49
-
50
- # set default values, with org_root if needed
51
- # the size of the UID is randomized
52
- # fixed_size is the size ogf the whole UID, with the org taken into account
53
- def self.random_dicom_uid org_root, fixed_size, odd_byte_boundary = true
54
-
55
- raise TypeError, 'Org root must be a string or an Integer' unless org_root.is_a? String or org_root.is_a? Integer
56
- org_root = org_root.to_s if org_root.is_a? Integer
57
- raise TypeError unless fixed_size.is_a? Integer and odd_byte_boundary == !!odd_byte_boundary
58
-
59
- # building the org root
60
- org_root = self.random_component(62, odd_byte_boundary) if org_root.empty?# UID needs at least an org root
61
- raise LeadingZeroError if leading_zero? org_root
62
- raise OddByteError if !odd_byte_rule(org_root) and odd_byte_boundary
63
-
64
- # if the fixed size doesn't exist, a random one is created, but
65
- # it must be generated so that the UID musn't be above 64 chars
66
- fixed_size ||= rand(0..(64 - org_root.length - 1))
67
- fixed_size -= 1 if add_missing_dot org_root
68
-
69
- raise OversizedUIDError if fixed_size > 64
70
- raise RangeError, 'Size of Org root larger than size provided' if fixed_size < org_root.length
71
- raise RangeError, "Size of UID can't be negative" if fixed_size < 0
72
-
73
- # building the suffix
74
- self.rand_duid org_root, (fixed_size - org_root.length), odd_byte_boundary
75
- end
76
-
77
-
78
-
79
70
  # Return an array of UIDs, from a common org root
80
71
  def self.random_uids org_root, fixed_size, array_size, odd_byte_boundary = true
81
72
  uids = Array.new array_size
@@ -87,8 +78,6 @@ module DicomUID
87
78
  uids
88
79
  end
89
80
 
90
-
91
-
92
81
  private
93
82
 
94
83
  # Generates recursively a random dicom uid
@@ -108,14 +97,8 @@ module DicomUID
108
97
  self.rand_duid uid, remain - 1, obb
109
98
  end
110
99
 
111
-
112
-
113
-
114
-
115
-
116
100
  end
117
101
 
118
-
119
102
  def add_missing_dot comp
120
103
  raise TypeError unless comp.is_a? String
121
104
  if comp[-1] != '.'
@@ -125,13 +108,11 @@ def add_missing_dot comp
125
108
  false
126
109
  end
127
110
 
128
-
129
111
  def odd_byte_rule comp
130
112
  return comp[-1].to_i % 2 == 0 || (comp[-2].to_i % 2 == 1 && comp[-1].to_i == 0) if comp.length != 1
131
113
  comp[-1].to_i % 2 == 0
132
114
  end
133
115
 
134
-
135
116
  def leading_zero? org_root
136
117
  org_root[0] == '0' and org_root.length != 1
137
118
  end
@@ -157,3 +138,4 @@ class OversizedUIDError < StandardError
157
138
  super
158
139
  end
159
140
  end
141
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Dicom_UID
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Repain Paul
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-03 00:00:00.000000000 Z
11
+ date: 2019-10-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Generates random UID for DICOM files
14
14
  email: paul.repain@yahoo.com