p15id 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 37d32a6ddf1393c6df96e3665656908df6e3d47a
4
+ data.tar.gz: 8ab6cdac51275c8796aac8a0f540d80b816111ed
5
+ SHA512:
6
+ metadata.gz: 3c36a469acba8173bd1ca9b03e9273a2fba25eb72e14b1fd65803faa3f422c88739e59904665a8edb3e90b23912f8e66769808ef5ab153c243c55b7c905c371d
7
+ data.tar.gz: 0a158d354c19b14398bbab64a9244f8d2e99c08c9a27d2beb839691a1cc2ad7401a7c23e14472cd48445a8d212e53225544e475415a2d1c0d90748c503b08e74
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in p15id.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,16 @@
1
+ guard :rspec, cmd: "bundle exec rspec" do
2
+ require "guard/rspec/dsl"
3
+ dsl = Guard::RSpec::Dsl.new(self)
4
+
5
+ # RSpec files
6
+ rspec = dsl.rspec
7
+ watch(rspec.spec_helper) { rspec.spec_dir }
8
+ watch(rspec.spec_support) { rspec.spec_dir }
9
+ watch(rspec.spec_files)
10
+
11
+ # Ruby files
12
+ ruby = dsl.ruby
13
+ dsl.watch_spec_files_for(ruby.lib_files)
14
+ watch(%r{^lib/p15id/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
15
+
16
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Michel Boaventura
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # P15id
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'p15id'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install p15id
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/p15id/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :test => :spec
7
+ task :default => :test
data/lib/p15id.rb ADDED
@@ -0,0 +1,4 @@
1
+ require "p15id/version"
2
+ require "p15id/field"
3
+ require "p15id/segment"
4
+ require "p15id/message"
@@ -0,0 +1,32 @@
1
+ module P15ID
2
+ class Field
3
+ attr_reader :field, :value
4
+
5
+ SEP = "\x16"
6
+ FIELD_END = "\x08"
7
+ MEASURE_LIST = %w{ Val Low High Unit Flag EditFlag HighLowFlag }
8
+ PATINFO_LIST = %w{ SampleID Name Gender AgeType AgeVal ChargeType
9
+ SamSourc ChartNo BedNo InsNo Dept Sender Tester Checker Remark }
10
+ LIST = MEASURE_LIST + PATINFO_LIST
11
+
12
+ #Val Parameter value indicated by SD field
13
+ #Low Lower limit of analysis result
14
+ #High Upper limit of analysis result
15
+ #Unit Unit of parameter
16
+ #Flag Suspect sign for parameters
17
+
18
+ def initialize(field:, value: "")
19
+ raise "Invalid field '#{field}'" unless LIST.include?(field)
20
+ @field = field
21
+ @value = value
22
+ end
23
+
24
+ def to_s(sep: ",", field_end: ";")
25
+ "#{@field}#{sep}#{@value}#{field_end}"
26
+ end
27
+
28
+ def to_bytes
29
+ to_s(sep: SEP, field_end: FIELD_END)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,31 @@
1
+ module P15ID
2
+ class Message
3
+ attr_reader :segments
4
+
5
+ MESSAGE_START = "\x05"
6
+ MESSAGE_END = "\x0a"
7
+ MESSAGE_DESCRIPTION = "CTR"
8
+ MD_SD_SEPARATOR = "\x03"
9
+
10
+ def initialize
11
+ @segments = []
12
+ end
13
+
14
+ def add_segment(segment)
15
+ return if @segments.any? { |s| s.segment == segment.segment }
16
+
17
+ @segments << segment
18
+ end
19
+
20
+ def to_s(segments: nil, message_start: "{", message_end: "}", md_sd_separator: "#")
21
+ segments ||= @segments.map(&:to_s).join
22
+ "#{message_start}#{MESSAGE_DESCRIPTION}#{md_sd_separator}#{segments}#{message_end}"
23
+ end
24
+
25
+ def to_bytes
26
+ segments = @segments.map(&:to_bytes).join
27
+ to_s(segments: segments, message_start: MESSAGE_START, message_end: MESSAGE_END, md_sd_separator: MD_SD_SEPARATOR)
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,41 @@
1
+ module P15ID
2
+ class Segment
3
+ attr_reader :segment, :fields
4
+
5
+ MEASURE = %w{ HCT HGB Lymph# Lymph% MCH MCHC MCV Mid# Mid% MPV Neu#
6
+ Neu% PCT PDW P-LCR PLT RBC RDW-CV RDW-SD WBC }
7
+ PATINFO = %w{ PatInfo }
8
+ LIST = MEASURE + PATINFO
9
+
10
+ SEGMENT_END = "\x04"
11
+ SD_FD_SEP = "\x0C"
12
+
13
+ def initialize(segment:)
14
+ raise "Invalid Segment '#{segment}'" unless LIST.include?(segment)
15
+
16
+ @segment = segment
17
+ @fields = []
18
+ end
19
+
20
+ def add_field(field)
21
+ return if @fields.any? { |f| f.field == field.field }
22
+
23
+ if (MEASURE.include?(@segment) && !Field::MEASURE_LIST.include?(field.field)) ||
24
+ (PATINFO.include?(@segment) && !Field::PATINFO_LIST.include?(field.field))
25
+ raise("Field '#{field.field}' not compatible with Segment '#{@segment}'")
26
+ end
27
+
28
+ @fields << field
29
+ end
30
+
31
+ def to_s(fields: nil, segment_end: "$", sd_fd_sep: ":")
32
+ fields ||= @fields.map(&:to_s).join
33
+ "#{@segment}#{sd_fd_sep}#{fields}#{segment_end}"
34
+ end
35
+
36
+ def to_bytes
37
+ fields = @fields.map(&:to_bytes).join
38
+ to_s(fields: fields, segment_end: SEGMENT_END, sd_fd_sep: SD_FD_SEP)
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,3 @@
1
+ module P15ID
2
+ VERSION = "0.0.1"
3
+ end
data/p15id.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'p15id/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "p15id"
8
+ spec.version = P15ID::VERSION
9
+ spec.authors = ["Michel Boaventura"]
10
+ spec.email = ["michel.boaventura@gmail.com"]
11
+ spec.summary = "15ID protocol implementation"
12
+ spec.description = "A Ruby's implementation of the 15ID protocol"
13
+ spec.homepage = "https://github.com/michelboaventura/p15id"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.3"
24
+ spec.add_development_dependency "guard-rspec", "~> 4.6"
25
+ end
@@ -0,0 +1,42 @@
1
+ require 'p15id'
2
+
3
+ include P15ID
4
+
5
+ describe Field do
6
+ context "Misc" do
7
+ it "doesn't initialize without arguments" do
8
+ expect{Field.new}.to raise_error(ArgumentError)
9
+ end
10
+ it "uses the right separator" do
11
+ expect(Field::SEP).to eq("\x16")
12
+ end
13
+ it "uses the right field end" do
14
+ expect(Field::FIELD_END).to eq("\x08")
15
+ end
16
+ end
17
+
18
+ context "Field descriptions and values" do
19
+ it "accepts valid field" do
20
+ expect{Field.new(field: "Val")}.not_to raise_error
21
+ end
22
+ it "throws exception with invalid field" do
23
+ expect{Field.new(field: "F")}.to raise_error("Invalid field 'F'")
24
+ end
25
+ it "doesn't requid a field's value" do
26
+ expect{Field.new(field: "Val")}.not_to raise_error
27
+ end
28
+ end
29
+
30
+ context "Exporting fields" do
31
+ subject { Field.new(field: "Val", value: "42.0") }
32
+
33
+ it "implements #to_s" do
34
+ expect(subject.to_s).to eq("Val,42.0;")
35
+ end
36
+
37
+ it "implements #to_bytes" do
38
+ expect(subject.to_bytes).to eq("Val\x1642.0\x08")
39
+ end
40
+ end
41
+
42
+ end
@@ -0,0 +1,266 @@
1
+ {
2
+ "CTR#" : {
3
+ "ALY%" : {
4
+ "Val" : "1.3",
5
+ "High" : "2.0",
6
+ "Flag" : "0",
7
+ "Unit" : "%",
8
+ "Low" : "0.0"
9
+ },
10
+ "LIC%" : {
11
+ "High" : "2.5",
12
+ "Val" : "0.2",
13
+ "Unit" : "%",
14
+ "Flag" : "0",
15
+ "Low" : "0.0"
16
+ },
17
+ "MCHC" : {
18
+ "HighLowFlag" : "L",
19
+ "Flag" : "0",
20
+ "Unit" : "g/L",
21
+ "Low" : "320",
22
+ "Val" : "304",
23
+ "High" : "360"
24
+ },
25
+ "GranYW" : {
26
+ "Low" : "*",
27
+ "Flag" : "0",
28
+ "Unit" : "",
29
+ "Val" : "*",
30
+ "High" : "*"
31
+ },
32
+ "Neu#" : {
33
+ "Low" : "2.00",
34
+ "Flag" : "0",
35
+ "Unit" : "10^9/L",
36
+ "Val" : "3.00",
37
+ "High" : "7.00"
38
+ },
39
+ "Mon%" : {
40
+ "Flag" : "0",
41
+ "Unit" : "%",
42
+ "Low" : "3.0",
43
+ "High" : "12.0",
44
+ "Val" : "7.4"
45
+ },
46
+ "Neu%" : {
47
+ "Val" : "31.5",
48
+ "High" : "70.0",
49
+ "HighLowFlag" : "L",
50
+ "Low" : "50.0",
51
+ "Unit" : "%",
52
+ "Flag" : "0"
53
+ },
54
+ "RBC" : {
55
+ "HighLowFlag" : "L",
56
+ "Flag" : "0",
57
+ "Unit" : "10^12/L",
58
+ "Low" : "4.00",
59
+ "Val" : "3.95",
60
+ "High" : "5.50"
61
+ },
62
+ "Lymph#" : {
63
+ "Low" : "0.80",
64
+ "Unit" : "10^9/L",
65
+ "Flag" : "0",
66
+ "Val" : "2.63",
67
+ "High" : "4.00"
68
+ },
69
+ "Eos#" : {
70
+ "Val" : "0.34",
71
+ "High" : "0.50",
72
+ "Low" : "0.02",
73
+ "Flag" : "0",
74
+ "Unit" : "10^9/L"
75
+ },
76
+ "PLT" : {
77
+ "Unit" : "10^9/L",
78
+ "Flag" : "0",
79
+ "Low" : "100",
80
+ "HighLowFlag" : "H",
81
+ "High" : "300",
82
+ "Val" : "362"
83
+ },
84
+ "GranX" : {
85
+ "Val" : "*",
86
+ "High" : "*",
87
+ "Flag" : "0",
88
+ "Unit" : "",
89
+ "Low" : "*"
90
+ },
91
+ "WBCBAX" : {
92
+ "High" : "*",
93
+ "Val" : "75",
94
+ "Unit" : "",
95
+ "Flag" : "0",
96
+ "Low" : "*"
97
+ },
98
+ "GranY" : {
99
+ "Unit" : "",
100
+ "Flag" : "0",
101
+ "Low" : "*",
102
+ "Val" : "*",
103
+ "High" : "*"
104
+ },
105
+ "MCV" : {
106
+ "Val" : "95.0",
107
+ "High" : "100.0",
108
+ "Flag" : "0",
109
+ "Unit" : "fL",
110
+ "Low" : "80.0"
111
+ },
112
+ "WBC" : {
113
+ "High" : "10.00",
114
+ "Val" : "9.55",
115
+ "Low" : "4.00",
116
+ "Unit" : "10^9/L",
117
+ "Flag" : "0"
118
+ },
119
+ "Bas%" : {
120
+ "High" : "1.0",
121
+ "Val" : "30.0",
122
+ "Flag" : "0",
123
+ "Unit" : "%",
124
+ "Low" : "0.0",
125
+ "HighLowFlag" : "H"
126
+ },
127
+ "MasDiff" : {
128
+ "Val" : "77.2",
129
+ "High" : "***.*",
130
+ "Unit" : "fL",
131
+ "Flag" : "0",
132
+ "Low" : "***.*"
133
+ },
134
+ "MasBaso" : {
135
+ "Val" : "75.8",
136
+ "High" : "***.*",
137
+ "Low" : "***.*",
138
+ "Unit" : "fL",
139
+ "Flag" : "0"
140
+ },
141
+ "LasDiff" : {
142
+ "Low" : "***.*",
143
+ "Flag" : "0",
144
+ "Unit" : "fL",
145
+ "High" : "***.*",
146
+ "Val" : "77.2"
147
+ },
148
+ "LIC#" : {
149
+ "Unit" : "10^9/L",
150
+ "Flag" : "0",
151
+ "Low" : "0.00",
152
+ "Val" : "0.02",
153
+ "High" : "0.20"
154
+ },
155
+ "Lymph%" : {
156
+ "Unit" : "%",
157
+ "Flag" : "0",
158
+ "Low" : "20.0",
159
+ "High" : "40.0",
160
+ "Val" : "27.5"
161
+ },
162
+ "RDW-CV" : {
163
+ "Low" : "11.0",
164
+ "Unit" : "%",
165
+ "Flag" : "0",
166
+ "Val" : "14.4",
167
+ "High" : "16.0"
168
+ },
169
+ "MCH" : {
170
+ "Low" : "27.0",
171
+ "Flag" : "0",
172
+ "Unit" : "pg",
173
+ "Val" : "28.9",
174
+ "High" : "34.0"
175
+ },
176
+ "WBCBAY" : {
177
+ "Low" : "*",
178
+ "Flag" : "0",
179
+ "Unit" : "",
180
+ "Val" : "68",
181
+ "High" : "*"
182
+ },
183
+ "LasBaso" : {
184
+ "Val" : "68.3",
185
+ "High" : "***.*",
186
+ "Low" : "***.*",
187
+ "Flag" : "0",
188
+ "Unit" : "fL"
189
+ },
190
+ "Mon#" : {
191
+ "Val" : "0.71",
192
+ "High" : "1.20",
193
+ "Flag" : "0",
194
+ "Unit" : "10^9/L",
195
+ "Low" : "0.12"
196
+ },
197
+ "Bas#" : {
198
+ "Val" : "2.87",
199
+ "High" : "0.10",
200
+ "HighLowFlag" : "H",
201
+ "Low" : "0.00",
202
+ "Unit" : "10^9/L",
203
+ "Flag" : "0"
204
+ },
205
+ "PDW" : {
206
+ "Val" : "14.4",
207
+ "High" : "17.0",
208
+ "Low" : "9.0",
209
+ "Flag" : "0",
210
+ "Unit" : ""
211
+ },
212
+ "MPV" : {
213
+ "High" : "12.0",
214
+ "Val" : "12.0",
215
+ "Low" : "6.5",
216
+ "Flag" : "0",
217
+ "Unit" : "fL"
218
+ },
219
+ "Eos%" : {
220
+ "Low" : "0.5",
221
+ "Flag" : "0",
222
+ "Unit" : "%",
223
+ "High" : "5.0",
224
+ "Val" : "3.6"
225
+ },
226
+ "PCT" : {
227
+ "HighLowFlag" : "H",
228
+ "Low" : "0.108",
229
+ "Unit" : "%",
230
+ "Flag" : "0",
231
+ "Val" : "0.434",
232
+ "High" : "0.282"
233
+ },
234
+ "ALY#" : {
235
+ "Flag" : "0",
236
+ "Unit" : "10^9/L",
237
+ "Low" : "0.00",
238
+ "High" : "0.20",
239
+ "Val" : "0.12"
240
+ },
241
+ "HCT" : {
242
+ "High" : "54.0",
243
+ "Val" : "37.5",
244
+ "Low" : "40.0",
245
+ "Flag" : "0",
246
+ "Unit" : "%",
247
+ "HighLowFlag" : "L"
248
+ },
249
+ "RDW-SD" : {
250
+ "HighLowFlag" : "H",
251
+ "Unit" : "fL",
252
+ "Flag" : "0",
253
+ "Low" : "35.0",
254
+ "Val" : "60.7",
255
+ "High" : "56.0"
256
+ },
257
+ "HGB" : {
258
+ "Val" : "114",
259
+ "High" : "160",
260
+ "HighLowFlag" : "L",
261
+ "Low" : "120",
262
+ "Unit" : "g/L",
263
+ "Flag" : "0"
264
+ }
265
+ }
266
+ }
@@ -0,0 +1,63 @@
1
+ require 'p15id'
2
+
3
+ include P15ID
4
+
5
+ describe Message do
6
+ context "Misc" do
7
+ it "uses the right message start" do
8
+ expect(Message::MESSAGE_START).to eq("\x05")
9
+ end
10
+ it "uses the right message end" do
11
+ expect(Message::MESSAGE_END).to eq("\x0a")
12
+ end
13
+ it "uses the right message description" do
14
+ expect(Message::MESSAGE_DESCRIPTION).to eq("CTR")
15
+ end
16
+ it "uses the right MD-SD separator" do
17
+ expect(Message::MD_SD_SEPARATOR).to eq("\x03")
18
+ end
19
+ end
20
+
21
+ context "Segments" do
22
+ it "accepts segments with #add_segments" do
23
+ msg = Message.new
24
+ segment = Segment.new(segment: "HCT")
25
+ msg.add_segment segment
26
+
27
+ expect(msg.segments).to eq([segment])
28
+ end
29
+ it "keeps the first segment if two of the same type are added" do
30
+ seg1 = Segment.new(segment: "HCT")
31
+ seg2 = Segment.new(segment: "HCT")
32
+ msg = Message.new
33
+
34
+ msg.add_segment seg1
35
+ msg.add_segment seg2
36
+
37
+ expect(msg.segments).to eq([seg1])
38
+ end
39
+ end
40
+
41
+ context "Exporting message" do
42
+ subject {
43
+ msg = Message.new
44
+ seg1 = Segment.new(segment: "HCT")
45
+ seg2 = Segment.new(segment: "HGB")
46
+
47
+ seg1.add_field Field.new(field: "Val", value: "41.0")
48
+ seg2.add_field Field.new(field: "Low", value: "22.0")
49
+
50
+ msg.add_segment seg1
51
+ msg.add_segment seg2
52
+
53
+ msg
54
+ }
55
+
56
+ it "implements #to_s" do
57
+ expect(subject.to_s).to eq("{CTR#HCT:Val,41.0;$HGB:Low,22.0;$}")
58
+ end
59
+ it "implements #to_bytes" do
60
+ expect(subject.to_bytes).to eq("\x05CTR\x03HCT\x0cVal\x1641.0\x08\x04HGB\x0cLow\x1622.0\x08\x04\x0a")
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,82 @@
1
+ require 'p15id'
2
+
3
+ include P15ID
4
+
5
+ describe Segment do
6
+ context "Misc" do
7
+ it "doesn't initialize without arguments" do
8
+ expect{Segment.new}.to raise_error(ArgumentError)
9
+ end
10
+ it "uses the right segment end" do
11
+ expect(Segment::SEGMENT_END).to eq("\x04")
12
+ end
13
+ it "uses the right SD-FD separator" do
14
+ expect(Segment::SD_FD_SEP).to eq("\x0C")
15
+ end
16
+ end
17
+
18
+ context "Segment descriptions" do
19
+ it "accepts valid segment" do
20
+ expect{Segment.new(segment: "HCT")}.not_to raise_error
21
+ end
22
+
23
+ it "throws exception with invalid segment" do
24
+ expect{Segment.new(segment: "F")}.to raise_error("Invalid Segment 'F'")
25
+ end
26
+ end
27
+
28
+ context "Fields" do
29
+ it "accepts fields with #add_field" do
30
+ field = Field.new(field: "Val", value: "42.0")
31
+ seg = Segment.new(segment: "HCT")
32
+ seg.add_field(field)
33
+
34
+ expect(seg.fields).to eq([field])
35
+ end
36
+
37
+ it "keeps the first field if two of the same type are added" do
38
+ field1 = Field.new(field: "Val", value: "41.0")
39
+ field2 = Field.new(field: "Val", value: "42.0")
40
+
41
+ seg = Segment.new(segment: "HCT")
42
+ seg.add_field(field1)
43
+ seg.add_field(field2)
44
+
45
+ expect(seg.fields).to eq([field1])
46
+ end
47
+
48
+ it "only accept fields which are valid for the segment" do
49
+ seg = Segment.new(segment: "HCT")
50
+ f1 = Field.new(field: "SampleID")
51
+
52
+ expect {seg.add_field f1}.to raise_error(
53
+ "Field 'SampleID' not compatible with Segment 'HCT'"
54
+ )
55
+
56
+ seg = Segment.new(segment: "PatInfo")
57
+ f1 = Field.new(field: "Val")
58
+
59
+ expect {seg.add_field f1}.to raise_error(
60
+ "Field 'Val' not compatible with Segment 'PatInfo'"
61
+ )
62
+
63
+ end
64
+ end
65
+
66
+ context "Exporting segment" do
67
+ subject {
68
+ seg = Segment.new(segment: "HCT")
69
+ seg.add_field Field.new(field: "Val", value: "41.0")
70
+ seg.add_field Field.new(field: "Low", value: "22.0")
71
+ seg
72
+ }
73
+
74
+ it "implements #to_s" do
75
+ expect(subject.to_s).to eq("HCT:Val,41.0;Low,22.0;$")
76
+ end
77
+
78
+ it "implements #to_bytes" do
79
+ expect(subject.to_bytes).to eq("HCT\x0CVal\x1641.0\x08Low\x1622.0\x08\x04")
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,63 @@
1
+ RSpec.configure do |config|
2
+ config.expect_with :rspec do |expectations|
3
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
4
+ end
5
+
6
+ config.mock_with :rspec do |mocks|
7
+ mocks.verify_partial_doubles = true
8
+ end
9
+
10
+ # The settings below are suggested to provide a good initial experience
11
+ # with RSpec, but feel free to customize to your heart's content.
12
+ =begin
13
+ # These two settings work together to allow you to limit a spec run
14
+ # to individual examples or groups you care about by tagging them with
15
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
16
+ # get run.
17
+ config.filter_run :focus
18
+ config.run_all_when_everything_filtered = true
19
+
20
+ # Allows RSpec to persist some state between runs in order to support
21
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
22
+ # you configure your source control system to ignore this file.
23
+ config.example_status_persistence_file_path = "spec/examples.txt"
24
+
25
+ # Limits the available syntax to the non-monkey patched syntax that is
26
+ # recommended. For more details, see:
27
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
28
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
29
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
30
+ config.disable_monkey_patching!
31
+
32
+ # This setting enables warnings. It's recommended, but in some cases may
33
+ # be too noisy due to issues in dependencies.
34
+ config.warnings = true
35
+
36
+ # Many RSpec users commonly either run the entire suite or an individual
37
+ # file, and it's useful to allow more verbose output when running an
38
+ # individual spec file.
39
+ if config.files_to_run.one?
40
+ # Use the documentation formatter for detailed output,
41
+ # unless a formatter has already been configured
42
+ # (e.g. via a command-line flag).
43
+ config.default_formatter = 'doc'
44
+ end
45
+
46
+ # Print the 10 slowest examples and example groups at the
47
+ # end of the spec run, to help surface which specs are running
48
+ # particularly slow.
49
+ config.profile_examples = 10
50
+
51
+ # Run specs in random order to surface order dependencies. If you find an
52
+ # order dependency and want to debug it, you can fix the order by providing
53
+ # the seed, which is printed after each run.
54
+ # --seed 1234
55
+ config.order = :random
56
+
57
+ # Seed global randomization in this process using the `--seed` CLI option.
58
+ # Setting this allows you to use `--seed` to deterministically reproduce
59
+ # test failures related to randomization by passing the same `--seed` value
60
+ # as the one that triggered the failure.
61
+ Kernel.srand config.seed
62
+ =end
63
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: p15id
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Michel Boaventura
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard-rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '4.6'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '4.6'
69
+ description: A Ruby's implementation of the 15ID protocol
70
+ email:
71
+ - michel.boaventura@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - Gemfile
79
+ - Guardfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - lib/p15id.rb
84
+ - lib/p15id/field.rb
85
+ - lib/p15id/message.rb
86
+ - lib/p15id/segment.rb
87
+ - lib/p15id/version.rb
88
+ - p15id.gemspec
89
+ - spec/field_spec.rb
90
+ - spec/fixtures/example.json
91
+ - spec/message_spec.rb
92
+ - spec/segment_spec.rb
93
+ - spec/spec_helper.rb
94
+ homepage: https://github.com/michelboaventura/p15id
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.4.8
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: 15ID protocol implementation
118
+ test_files:
119
+ - spec/field_spec.rb
120
+ - spec/fixtures/example.json
121
+ - spec/message_spec.rb
122
+ - spec/segment_spec.rb
123
+ - spec/spec_helper.rb