rtp-connect 1.0 → 1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,6 +5,12 @@ module RTP
5
5
  attr_reader :keyword
6
6
  attr_reader :crc
7
7
 
8
+ # Setting the keyword attribute.
9
+ #
10
+ def crc=(value)
11
+ @crc = value.to_s
12
+ end
13
+
8
14
  # Encodes a string from the contents of this instance.
9
15
  # This produces the full line, including a computed CRC checksum.
10
16
  #
@@ -25,11 +31,10 @@ module RTP
25
31
  end
26
32
  end
27
33
 
28
- # Setting the keyword attribute.
34
+ # Returns self.
29
35
  #
30
- def crc=(value)
31
- raise ArgumentError, "Invalid argument 'value'. Expected String, got #{value.class}." unless value.is_a?(String)
32
- @crc = value
36
+ def to_record
37
+ self
33
38
  end
34
39
 
35
40
  end
@@ -37,7 +37,7 @@ class String
37
37
  # and the resulting quote-less value strings are returned in an array.
38
38
  #
39
39
  def values
40
- original = self.split(',')
40
+ original = CSV.parse(self).first
41
41
  processed = Array.new
42
42
  original.collect {|element| processed << element.gsub('"', '')}
43
43
  return processed
@@ -34,10 +34,8 @@ module RTP
34
34
  # * <tt>parent</tt> -- A Record which is used to determine the proper parent of this instance.
35
35
  #
36
36
  def self.load(string, parent)
37
- raise ArgumentError, "Invalid argument 'string'. Expected String, got #{string.class}." unless string.is_a?(String)
38
- raise ArgumentError, "Invalid argument 'parent'. Expected RTP::Prescription, got #{parent.class}." unless parent.is_a?(RTP::Prescription)
39
37
  # Get the quote-less values:
40
- values = string.values
38
+ values = string.to_s.values
41
39
  raise ArgumentError, "Invalid argument 'string': Expected exactly 16 elements, got #{values.length}." unless values.length == 16
42
40
  s = self.new(parent)
43
41
  # Assign the values to attributes:
@@ -67,19 +65,34 @@ module RTP
67
65
  # * <tt>parent</tt> -- A Record which is used to determine the proper parent of this instance.
68
66
  #
69
67
  def initialize(parent)
70
- raise ArgumentError, "Invalid argument 'parent'. Expected RTP::Prescription, got #{parent.class}." unless parent.is_a?(RTP::Prescription)
71
- # Parent relation:
72
- @parent = get_parent(parent, Prescription)
68
+ # Parent relation (always expecting a Prescription here):
69
+ @parent = get_parent(parent.to_prescription, Prescription)
73
70
  @parent.add_site_setup(self)
74
71
  @keyword = 'SITE_SETUP_DEF'
75
72
  end
76
73
 
74
+ # Returns true if the argument is an instance with attributes equal to self.
75
+ #
76
+ def ==(other)
77
+ if other.respond_to?(:to_site_setup)
78
+ other.send(:state) == state
79
+ end
80
+ end
81
+
82
+ alias_method :eql?, :==
83
+
77
84
  # Returns an empty array, as these instances are child-less by definition.
78
85
  #
79
86
  def children
80
87
  return Array.new
81
88
  end
82
89
 
90
+ # Generates a Fixnum hash value for this instance.
91
+ #
92
+ def hash
93
+ state.hash
94
+ end
95
+
83
96
  # Returns the values of this instance in an array.
84
97
  # The values does not include the CRC.
85
98
  #
@@ -106,122 +119,124 @@ module RTP
106
119
  # Writes the SiteSetup object + any hiearchy of child objects,
107
120
  # to a properly formatted RTPConnect ascii string.
108
121
  #
109
- def to_str
122
+ def to_s
110
123
  str = encode
111
124
  if children
112
125
  children.each do |child|
113
- str += child.to_str
126
+ str += child.to_s
114
127
  end
115
128
  end
116
129
  return str
117
130
  end
118
131
 
132
+ alias :to_str :to_s
133
+
134
+ # Returns self.
135
+ #
136
+ def to_site_setup
137
+ self
138
+ end
139
+
119
140
  # Sets the keyword attribute.
120
141
  #
121
142
  def keyword=(value)
122
- raise ArgumentError, "Invalid argument 'value'. Expected String, got #{value.class}." unless value.is_a?(String)
123
- raise ArgumentError, "Invalid keyword. Expected 'SITE_SETUP_DEF', got #{value}." unless value.upcase == "SITE_SETUP_DEF"
143
+ value = value.to_s.upcase
144
+ raise ArgumentError, "Invalid keyword. Expected 'SITE_SETUP_DEF', got #{value}." unless value == "SITE_SETUP_DEF"
124
145
  @keyword = value
125
146
  end
126
147
 
127
148
  # Sets the rx_site_name attribute.
128
149
  #
129
150
  def rx_site_name=(value)
130
- raise ArgumentError, "Invalid argument 'value'. Expected String, got #{value.class}." unless value.is_a?(String)
131
- @rx_site_name = value
151
+ @rx_site_name = value && value.to_s
132
152
  end
133
153
 
134
154
  # Sets the patient_orientation attribute.
135
155
  #
136
156
  def patient_orientation=(value)
137
- raise ArgumentError, "Invalid argument 'value'. Expected String, got #{value.class}." unless value.is_a?(String)
138
- @patient_orientation = value
157
+ @patient_orientation = value && value.to_s
139
158
  end
140
159
 
141
160
  # Sets the treatment_machine attribute.
142
161
  #
143
162
  def treatment_machine=(value)
144
- raise ArgumentError, "Invalid argument 'value'. Expected String, got #{value.class}." unless value.is_a?(String)
145
- @treatment_machine = value
163
+ @treatment_machine = value && value.to_s
146
164
  end
147
165
 
148
166
  # Sets the tolerance_table attribute.
149
167
  #
150
168
  def tolerance_table=(value)
151
- raise ArgumentError, "Invalid argument 'value'. Expected String, got #{value.class}." unless value.is_a?(String)
152
- @tolerance_table = value
169
+ @tolerance_table = value && value.to_s
153
170
  end
154
171
 
155
172
  # Sets the iso_pos_x attribute.
156
173
  #
157
174
  def iso_pos_x=(value)
158
- raise ArgumentError, "Invalid argument 'value'. Expected String, got #{value.class}." unless value.is_a?(String)
159
- @iso_pos_x = value
175
+ @iso_pos_x = value && value.to_s
160
176
  end
161
177
 
162
178
  # Sets the iso_pos_y attribute.
163
179
  #
164
180
  def iso_pos_y=(value)
165
- raise ArgumentError, "Invalid argument 'value'. Expected String, got #{value.class}." unless value.is_a?(String)
166
- @iso_pos_y = value
181
+ @iso_pos_y = value && value.to_s
167
182
  end
168
183
 
169
184
  # Sets the iso_pos_z attribute.
170
185
  #
171
186
  def iso_pos_z=(value)
172
- raise ArgumentError, "Invalid argument 'value'. Expected String, got #{value.class}." unless value.is_a?(String)
173
- @iso_pos_z = value
187
+ @iso_pos_z = value && value.to_s
174
188
  end
175
189
 
176
190
  # Sets the structure_set_uid attribute.
177
191
  #
178
192
  def structure_set_uid=(value)
179
- raise ArgumentError, "Invalid argument 'value'. Expected String, got #{value.class}." unless value.is_a?(String)
180
- @structure_set_uid = value
193
+ @structure_set_uid = value && value.to_s
181
194
  end
182
195
 
183
196
  # Sets the frame_of_ref_uid attribute.
184
197
  #
185
198
  def frame_of_ref_uid=(value)
186
- raise ArgumentError, "Invalid argument 'value'. Expected String, got #{value.class}." unless value.is_a?(String)
187
- @frame_of_ref_uid = value
199
+ @frame_of_ref_uid = value && value.to_s
188
200
  end
189
201
 
190
202
  # Sets the couch_vertical attribute.
191
203
  #
192
204
  def couch_vertical=(value)
193
- raise ArgumentError, "Invalid argument 'value'. Expected String, got #{value.class}." unless value.is_a?(String)
194
- @couch_vertical = value
205
+ @couch_vertical = value && value.to_s
195
206
  end
196
207
 
197
208
  # Sets the couch_lateral attribute.
198
209
  #
199
210
  def couch_lateral=(value)
200
- raise ArgumentError, "Invalid argument 'value'. Expected String, got #{value.class}." unless value.is_a?(String)
201
- @couch_lateral = value
211
+ @couch_lateral = value && value.to_s
202
212
  end
203
213
 
204
214
  # Sets the couch_longitudinal attribute.
205
215
  #
206
216
  def couch_longitudinal=(value)
207
- raise ArgumentError, "Invalid argument 'value'. Expected String, got #{value.class}." unless value.is_a?(String)
208
- @couch_longitudinal = value
217
+ @couch_longitudinal = value && value.to_s
209
218
  end
210
219
 
211
220
  # Sets the couch_angle attribute.
212
221
  #
213
222
  def couch_angle=(value)
214
- raise ArgumentError, "Invalid argument 'value'. Expected String, got #{value.class}." unless value.is_a?(String)
215
- @couch_angle = value
223
+ @couch_angle = value && value.to_s
216
224
  end
217
225
 
218
226
  # Sets the couch_pedestal attribute.
219
227
  #
220
228
  def couch_pedestal=(value)
221
- raise ArgumentError, "Invalid argument 'value'. Expected String, got #{value.class}." unless value.is_a?(String)
222
- @couch_pedestal = value
229
+ @couch_pedestal = value && value.to_s
223
230
  end
224
231
 
232
+
233
+ private
234
+
235
+
236
+ # Returns the attributes of this instance in an array (for comparison purposes).
237
+ #
238
+ alias_method :state, :values
239
+
225
240
  end
226
241
 
227
242
  end
@@ -1,6 +1,6 @@
1
1
  module RTP
2
2
 
3
3
  # The RTPConnect library version string.
4
- VERSION = "1.0"
4
+ VERSION = "1.1"
5
5
 
6
6
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: rtp-connect
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: "1.0"
5
+ version: "1.1"
6
6
  platform: ruby
7
7
  authors:
8
8
  - Christoffer Lervag
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-12-30 00:00:00 Z
13
+ date: 2012-04-18 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -42,7 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - ">="
44
44
  - !ruby/object:Gem::Version
45
- version: 2.7.0
45
+ version: 2.9.0
46
46
  type: :development
47
47
  version_requirements: *id003
48
48
  - !ruby/object:Gem::Dependency
@@ -53,7 +53,7 @@ dependencies:
53
53
  requirements:
54
54
  - - ">="
55
55
  - !ruby/object:Gem::Version
56
- version: 0.10.0
56
+ version: 0.10.5
57
57
  type: :development
58
58
  version_requirements: *id004
59
59
  description: RTPConnect is a file format used in radiotherapy for export & import of treatment planning data.