edfize 0.1.0.beta1 → 0.1.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 07173882caa9f634f306d9f351e05213db2bd7b4
4
- data.tar.gz: 0b78baa7a05690594bcd77afa437cdd864ef3fae
3
+ metadata.gz: 44aeaf1024f15eadb70e994e4f768d7e23e55073
4
+ data.tar.gz: a92347e4a34b965c09ba1d751582d0cc0bf56ec4
5
5
  SHA512:
6
- metadata.gz: a77a87ed38e265fa516302a98643a9f2f1810b1f6b7c46e57bb92372d8fa0936c5a1359a4f7b7ee3bc41985550ee3276d913bf3cbad3d7b6638ca2efee32b3ae
7
- data.tar.gz: 154f9505e976ccacbbbfab96d94d2f9d2c29f2b74edbf039a888f430c512bca2feed80658782f6b4c4cdf9373e006c2db713db1b24f251e4011f051867d78947
6
+ metadata.gz: b809d63028034dc994a9b8dfaeae8cecf37f1195f2a4bef625c3239537ed590dcf96ce0ad80a86b5119748e1db9a2e4c497cfbaf5bdca8f3703b6f007ef40a94
7
+ data.tar.gz: c6b392c72163d72bf23082699c4d4020bd1e86973f286a33a79eb9070a192d18a7ce86018be7322815a33f339eb8071e33f0bba26abd29297d573b504eca70e8
data/CHANGELOG.md CHANGED
@@ -1,8 +1,14 @@
1
1
  ## 0.1.0
2
2
  - Initial EDF class to load headers and signals into Ruby objects
3
3
  - `edfize` command has the following actions:
4
- - `check`: Validates EDFs in the current directory for errors
5
- - `test`: Same as `check`
4
+ - `test`: Validates EDFs in the current directory for errors
5
+ - To only show failing tests, add the flag `--failing`
6
+ - `edfize test --failing`
7
+ - To suppress descriptive test failures, add the flag `--quiet`
8
+ - `edfize test --quiet`
9
+ - Both flags can be used together
10
+ - `edfize test --failing --quiet`
11
+ - `check`: Same as `test`
6
12
  - `run`: Prints out the headers of all edfs in the current directory
7
13
  - `help`: Displays information about `edfize` along with all available commands
8
14
  - `version`: Displays the current `edfize` version
@@ -10,3 +16,7 @@
10
16
  - Expected Length Check: The expected total size is computed from the (`number
11
17
  of data records` * `total samples across all signals`) + `size of header` and
12
18
  this is compared to the actual file size.
19
+ - Reserved Area Checks: The header and the individual header reserved areas are
20
+ checked to validate that they are blank. Non-blank areas are a sign that the
21
+ edf header is corrupt and that data from the signal data block have leaked into
22
+ the header itself.
data/README.md CHANGED
@@ -24,10 +24,20 @@ Or install it yourself as:
24
24
 
25
25
  ### Validate EDFs
26
26
 
27
- Use `edfize check` to check that EDFs stored in the current directory have a valid format.
27
+ Use `edfize test` to test that EDFs stored in the current directory have a valid format.
28
28
 
29
29
  cd <edf-directory>
30
- edfize check
30
+ edfize test
31
+
32
+ A list of validations performed is:
33
+
34
+ - **Expected Length Check**: Compares the calculated size of the file based on signal sizes defined in the header with the actual file size. A failure may indicate corruption in the header (if the expected is less than the actual file size), or a partial/truncated file (if the expected is more than the actual file size).
35
+ - **Reserved Area Checks**: Check that reserved areas are blank. Non-blank reserved areas can indicate a sign of header or EDF file corruption.
36
+
37
+ Flags that can be added to the `test` command include:
38
+
39
+ - `--failing`: Only display EDFs with failing tests
40
+ - `--quiet`: Suppress detailed failure descriptions that show the expected versus the actual result of the test
31
41
 
32
42
  ### Print Signal Header information
33
43
 
@@ -54,6 +64,119 @@ Use `gem install edfize` to update Edfize to the latest stable
54
64
 
55
65
  Use `gem install edfize --pre` to update Edfize to the latest prerelease
56
66
 
67
+ ### Example of how to Load and Analyze EDFs in a Ruby Script
68
+
69
+ The following Ruby file demonstrates how to make use of the Edfize gem to load EDF signals into arrays for analysis.
70
+
71
+ `tutorial_01_load_edf_and_signals.rb`
72
+ ```ruby
73
+ # Tutorial 01 - Load EDF and Signals
74
+ #
75
+ # gem install edfize
76
+ #
77
+ # ruby tutorial_01_load_edf_and_signals.rb
78
+ #
79
+ # The EDF exists at:
80
+ #
81
+ # https://sleepdata.org/datasets/shhs/files/edfs/shhs1?f=shhs1-200001.edf
82
+ #
83
+
84
+ require 'rubygems'
85
+ require 'edfize'
86
+
87
+ # Loads the file and reads the EDF Header
88
+ edf = Edfize::Edf.new('shhs1-200001.edf')
89
+
90
+ # Loads the data section of the EDF into Signal objects
91
+ edf.load_signals
92
+
93
+ # Print out information on the signals
94
+ puts "EDF #{edf.filename} contains the following #{edf.signals.count} signal#{'s' unless edf.signals.count == 1}:\n\n"
95
+
96
+ edf.signals.each do |signal|
97
+ puts "Signal"
98
+ puts " Label : #{signal.label}"
99
+ puts " Samples Per Data Record: #{signal.samples_per_data_record}"
100
+ puts " First 10 Samples : #{(signal.samples[0..10] + ['...']).inspect}\n\n"
101
+ end
102
+ ```
103
+
104
+ When run, the code above will output the following:
105
+
106
+ ```console
107
+ EDF shhs1-200001.edf contains the following 14 signals:
108
+
109
+ Signal
110
+ Label : SaO2
111
+ Samples Per Data Record: 1
112
+ First 10 Samples : [29695, 29695, 29695, 29695, 29695, 29695, 29695, 29695, 28927, 28927, 28927, "..."]
113
+
114
+ Signal
115
+ Label : H.R.
116
+ Samples Per Data Record: 1
117
+ First 10 Samples : [-12493, -12493, -12493, -12697, -12697, -12697, -13107, -13107, -13107, -13107, -13107, "..."]
118
+
119
+ Signal
120
+ Label : EEG(sec)
121
+ Samples Per Data Record: 125
122
+ First 10 Samples : [-5, -13, -2, -13, -23, 1, 21, -9, 6, -17, 6, "..."]
123
+
124
+ Signal
125
+ Label : ECG
126
+ Samples Per Data Record: 125
127
+ First 10 Samples : [3, 7, -10, 0, 5, 4, 0, 3, 11, -12, -3, "..."]
128
+
129
+ Signal
130
+ Label : EMG
131
+ Samples Per Data Record: 125
132
+ First 10 Samples : [51, 9, -48, 84, 10, -23, 20, -10, 58, 2, 26, "..."]
133
+
134
+ Signal
135
+ Label : EOG(L)
136
+ Samples Per Data Record: 50
137
+ First 10 Samples : [29, 3, -127, 15, -67, 47, -3, -33, -25, 16, 28, "..."]
138
+
139
+ Signal
140
+ Label : EOG(R)
141
+ Samples Per Data Record: 50
142
+ First 10 Samples : [12, 25, 127, -106, 59, -3, 9, 7, 20, 7, -7, "..."]
143
+
144
+ Signal
145
+ Label : EEG
146
+ Samples Per Data Record: 125
147
+ First 10 Samples : [-3, 31, 65, 4, 52, 12, -2, 21, -26, 34, -9, "..."]
148
+
149
+ Signal
150
+ Label : THOR RES
151
+ Samples Per Data Record: 10
152
+ First 10 Samples : [-27, 17, -25, -57, 18, -24, 6, 32, 38, -21, 41, "..."]
153
+
154
+ Signal
155
+ Label : ABDO RES
156
+ Samples Per Data Record: 10
157
+ First 10 Samples : [-40, 34, -2, -28, 68, -117, -20, -24, 5, -27, 67, "..."]
158
+
159
+ Signal
160
+ Label : POSITION
161
+ Samples Per Data Record: 1
162
+ First 10 Samples : [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, "..."]
163
+
164
+ Signal
165
+ Label : LIGHT
166
+ Samples Per Data Record: 1
167
+ First 10 Samples : [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, "..."]
168
+
169
+ Signal
170
+ Label : NEW AIR
171
+ Samples Per Data Record: 10
172
+ First 10 Samples : [6, 7, 3, 3, 7, 3, 6, 0, 5, 5, 9, "..."]
173
+
174
+ Signal
175
+ Label : OX stat
176
+ Samples Per Data Record: 1
177
+ First 10 Samples : [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, "..."]
178
+ ```
179
+
57
180
  ## Contributing
58
181
 
59
182
  1. Fork it ( https://github.com/sleepepi/edfize/fork )
data/lib/edfize/edf.rb CHANGED
@@ -2,13 +2,28 @@ require 'edfize/signal'
2
2
 
3
3
  module Edfize
4
4
  class Edf
5
- attr_reader :signals, :filename
5
+ attr_reader :filename
6
+
7
+ attr_reader :reserved # 44 bytes - ASCII
8
+ attr_reader :number_of_data_records # 8 bytes - ASCII
9
+
10
+ attr_accessor :signals
11
+
12
+ RESERVED_SIZE = 44
13
+
14
+
6
15
 
7
16
  HEADER_OFFSET = 256
17
+ SIZE_OF_SAMPLE_IN_BYTES = 2
8
18
 
9
19
  def initialize(filename)
10
20
  @filename = filename
11
21
  @signals = []
22
+
23
+ read_header
24
+
25
+ # Other
26
+ get_number_of_data_records
12
27
  signal_labels
13
28
  transducer_types
14
29
  physical_dimensions
@@ -17,12 +32,12 @@ module Edfize
17
32
  digital_minimums
18
33
  digital_maximums
19
34
  prefilterings
20
- samples_in_data_records
35
+ samples_per_data_records
21
36
  reserved_areas
22
37
  end
23
38
 
24
- def size
25
- File.size(@filename)
39
+ def load_signals
40
+ get_data_records
26
41
  end
27
42
 
28
43
  def size_of_header
@@ -33,55 +48,61 @@ module Edfize
33
48
  256 + (ns * 256)
34
49
  end
35
50
 
36
- def total_size
37
- IO.binread(@filename).size
51
+ # Total File Size In Bytes
52
+ def edf_size
53
+ File.size(@filename)
38
54
  end
39
55
 
56
+ # Data Section Size In Bytes
40
57
  def expected_data_size
41
- result = 0
42
- @signals.each do |signal|
43
- result += signal.samples_in_data_record.to_i * 2 # NR * Int(16)
44
- end
45
- result * number_of_data_records.to_i
58
+ @signals.collect(&:samples_per_data_record).inject(:+).to_i * @number_of_data_records * SIZE_OF_SAMPLE_IN_BYTES
46
59
  end
47
60
 
48
- def expected_total_size
61
+ def expected_edf_size
49
62
  expected_data_size + size_of_header
50
- # (duration_of_a_data_record.to_i * number_of_data_records.to_i * number_of_signals.to_i) * 8
51
63
  end
52
64
 
53
65
  def print_header
54
- puts @filename
55
- puts "#{size} bytes (Total File Size)"
56
- puts "'#{header_version}' (0)"
57
- puts "'#{header_local_patient_identification}' (local patient identification)"
58
- puts "'#{header_local_recording_identification}' (local recording indentification)"
59
- puts "'#{header_start_date_of_recording}' (dd.mm.yy start date of recording)"
60
- puts "'#{header_start_time_of_recording}' (hh.mm.ss start time of recording)"
61
- # puts "--- RESERVED"
62
- puts "'#{number_of_data_records}' (number of data records, -1 if unknown)"
63
- puts "'#{duration_of_a_data_record}' seconds (duration of a data record)"
64
- puts "'#{number_of_signals}' number of signals (ns) in data record"
66
+ puts "\nEDF : #{@filename}"
67
+ puts "Total File Size : #{edf_size} bytes"
68
+ puts "\nHeader Information"
69
+ puts "Version : #{header_version}"
70
+ puts "Local Patient Identification : #{header_local_patient_identification}"
71
+ puts "Local Recording Identification : #{header_local_recording_identification}"
72
+ puts "Start Date of Recording : #{header_start_date_of_recording} (dd.mm.yy)"
73
+ puts "Start Time of Recording : #{header_start_time_of_recording} (hh.mm.ss)"
74
+ puts "Reserved : '#{@reserved}'"
75
+ puts "Number of Data Records : #{number_of_data_records}"
76
+ puts "Duration of a Data Record : #{duration_of_a_data_record.to_i} second#{'s' unless duration_of_a_data_record.to_i == 1}"
77
+ puts "Number of Signals (NS) : #{number_of_signals}"
78
+ puts "\nSignal Information"
65
79
  signals.each_with_index do |signal, index|
66
- puts "'#{signal.label}' (signal[#{index+1}] label)"
67
- puts "'#{signal.physical_dimension}' (signal[#{index+1}] physical_dimension)"
68
- puts "'#{signal.transducer_type}' (signal[#{index+1}] transducer_type)"
69
- puts "'#{signal.physical_minimum}' (signal[#{index+1}] physical_minimum)"
70
- puts "'#{signal.physical_maximum}' (signal[#{index+1}] physical_maximum)"
71
- puts "'#{signal.digital_minimum}' (signal[#{index+1}] digital_minimum)"
72
- puts "'#{signal.digital_maximum}' (signal[#{index+1}] digital_maximum)"
73
- puts "'#{signal.prefiltering}' (signal[#{index+1}] prefiltering)"
74
- puts "'#{signal.samples_in_data_record}' (signal[#{index+1}] samples_in_data_record)"
75
- puts "'#{signal.reserved_area}' (signal[#{index+1}] reserved_area)"
80
+ puts "\n Position : #{index + 1}"
81
+ puts " Label : #{signal.label}"
82
+ puts " Physical Dimension : #{signal.physical_dimension}"
83
+ puts " Transducer Type : #{signal.transducer_type}"
84
+ puts " Physical Minimum : #{signal.physical_minimum}"
85
+ puts " Physical Maximum : #{signal.physical_maximum}"
86
+ puts " Digital Minimum : #{signal.digital_minimum}"
87
+ puts " Digital Maximum : #{signal.digital_maximum}"
88
+ puts " Prefiltering : #{signal.prefiltering}"
89
+ puts " Samples Per Data Record : #{signal.samples_per_data_record}"
90
+ puts " Reserved Area : '#{signal.reserved_area}'"
76
91
  end
77
- puts "#{size} bytes (Total File Size)"
78
- puts "Size of Header (bytes) : #{size_of_header}"
79
- puts "Size of Data (bytes) : #{data_size}"
80
- puts "Total Size (bytes) : #{total_size}"
92
+ puts "\nGeneral Information"
93
+ puts "Size of Header (bytes) : #{size_of_header}"
94
+ puts "Size of Data (bytes) : #{data_size}"
95
+ puts "Total Size (bytes) : #{edf_size}"
96
+
97
+ puts "Expected Size of Header (bytes): #{expected_size_of_header}"
98
+ puts "Expected Size of Data (bytes): #{expected_data_size}"
99
+ puts "Expected Total Size (bytes): #{expected_edf_size}"
100
+ end
101
+
102
+ protected
81
103
 
82
- puts "Expected Size of Header (bytes) : #{expected_size_of_header}"
83
- puts "Expected Size of Data (bytes) : #{expected_data_size}"
84
- puts "Expected Total Size (bytes) : #{expected_total_size}"
104
+ def read_header
105
+ read_reserved
85
106
  end
86
107
 
87
108
  def header_version
@@ -114,13 +135,13 @@ module Edfize
114
135
  end
115
136
 
116
137
  # 44 ascii : reserved
117
- # def reserved
118
- # IO.binread(@filename, 44, 192)
119
- # end
138
+ def read_reserved
139
+ @reserved = IO.binread(@filename, RESERVED_SIZE, 192)
140
+ end
120
141
 
121
142
  # 8 ascii : number of data records (-1 if unknown, obey item 10 of the additional EDF+ specs)
122
- def number_of_data_records
123
- IO.binread(@filename, 8, 236)
143
+ def get_number_of_data_records
144
+ @number_of_data_records = IO.binread(@filename, 8, RESERVED_SIZE + 192).to_i
124
145
  end
125
146
 
126
147
  # 8 ascii : duration of a data record, in seconds
@@ -210,11 +231,12 @@ module Edfize
210
231
  end
211
232
 
212
233
  # ns * 8 ascii : ns * nr of samples in each data record
213
- def samples_in_data_records
234
+ def samples_per_data_records
214
235
  offset = HEADER_OFFSET + ns * (16 + 80 + 8 + 8 + 8 + 8 + 8 + 80)
215
236
  (0..ns-1).to_a.each do |signal_number|
216
237
  @signals[signal_number] ||= Signal.new()
217
- @signals[signal_number].samples_in_data_record = IO.binread(@filename, 8, offset+(signal_number*8))
238
+ @signals[signal_number].samples_per_data_record = IO.binread(@filename, 8, offset+(signal_number*8)).to_i
239
+ @signals[signal_number].samples = Array.new(@signals[signal_number].samples_per_data_record, 0)
218
240
  end
219
241
  end
220
242
 
@@ -227,28 +249,22 @@ module Edfize
227
249
  end
228
250
  end
229
251
 
230
- def get_samples
231
- offset = size_of_header
232
- current_read_offset = 0
233
- (0..ns-1).to_a.each do |signal_number|
234
- @signals[signal_number] ||= Signal.new()
235
- read_size = @signals[signal_number].samples_in_data_record.to_i * 2 * number_of_data_records.to_i
236
- @signals[signal_number].samples = IO.binread(@filename, read_size, size_of_header + current_read_offset).unpack('s*')
237
- current_read_offset += read_size
238
- end
239
- end
240
252
 
241
- # 2-byte integer
242
- # [16Bit]signed short: -32767 to 32767
243
- # .unpack('s*')
244
- def data_signals
245
- data_section = IO.binread(@filename, nil, size_of_header)
246
- dataset_section.unpack('s*')
253
+ #
254
+ def get_data_records
255
+ current_read_offset = size_of_header
256
+ (0..@number_of_data_records-1).to_a.each do |data_record_index|
257
+ @signals.each do |signal|
258
+ # 16-bit signed integer size = 2 Bytes = 2 ASCII characters
259
+ read_size = signal.samples_per_data_record * SIZE_OF_SAMPLE_IN_BYTES
260
+ signal.samples[data_record_index..data_record_index+signal.samples_per_data_record] = IO.binread(@filename, read_size, current_read_offset).unpack('s*')
261
+ current_read_offset += read_size
262
+ end
263
+ end
247
264
  end
248
265
 
249
266
  def data_size
250
- data_section = IO.binread(@filename, nil, size_of_header)
251
- data_section.size
267
+ IO.binread(@filename, nil, size_of_header).size
252
268
  end
253
269
  end
254
270
  end
data/lib/edfize/signal.rb CHANGED
@@ -1,21 +1,9 @@
1
1
  module Edfize
2
2
  class Signal
3
- attr_accessor :label, :transducer_type, :physical_dimension, :physical_minimum, :physical_maximum,
4
- :digital_minimum, :digital_maximum, :prefiltering, :samples_in_data_record, :reserved_area, :samples
5
-
6
- def initialize
7
- @label = ''
8
- @physical_dimension = ''
9
- @transducer_type = ''
10
- @physical_minimum = ''
11
- @physical_maximum = ''
12
- @digital_minimum = ''
13
- @digital_maximum = ''
14
- @prefiltering = ''
15
- @samples_in_data_record = ''
16
- @reserved_area = ''
17
- @samples = []
18
- end
19
-
3
+ attr_accessor :label, :transducer_type, :physical_dimension,
4
+ :physical_minimum, :physical_maximum,
5
+ :digital_minimum, :digital_maximum,
6
+ :prefiltering, :samples_per_data_record,
7
+ :reserved_area, :samples
20
8
  end
21
9
  end
@@ -1,15 +1,16 @@
1
1
  module Edfize
2
2
  module Tests
3
- # This test checks that the length calculated from the EDF header matches
4
- # the total length of the file
5
- def self.test_expected_length(edf)
6
- passes = (edf.expected_total_size == edf.total_size)
7
- puts " #{passes ? 'PASS' : 'FAIL'}".colorize( passes ? :green : :red ) + " Expected File Size"
8
- unless passes or not verbose
9
- puts " Expected : #{edf.expected_total_size} bytes"
10
- puts " Actual : #{edf.total_size} bytes"
3
+ module CheckLength
4
+ # This test checks that the length calculated from the EDF header matches
5
+ # the total length of the file
6
+ def test_expected_length(runner)
7
+ result = Result.new
8
+ result.passes = (runner.edf.expected_edf_size == runner.edf.edf_size)
9
+ result.pass_fail = " #{result.passes ? 'PASS' : 'FAIL'}".colorize( result.passes ? :green : :red ) + " Expected File Size"
10
+ result.expected = " Expected : #{runner.edf.expected_edf_size} bytes"
11
+ result.actual = " Actual : #{runner.edf.edf_size} bytes"
12
+ result
11
13
  end
12
- passes
13
14
  end
14
15
  end
15
16
  end
@@ -0,0 +1,15 @@
1
+ module Edfize
2
+ module Tests
3
+ module CheckReservedArea
4
+ # This test checks that the reserved area in the header is blank
5
+ def test_reserved_area_blank(runner)
6
+ result = Result.new
7
+ result.passes = (runner.edf.reserved == ' ' * Edf::RESERVED_SIZE)
8
+ result.pass_fail = " #{result.passes ? 'PASS' : 'FAIL'}".colorize( result.passes ? :green : :red ) + " Reserved Area Blank"
9
+ result.expected = " Expected : #{(' ' * Edf::RESERVED_SIZE).inspect}"
10
+ result.actual = " Actual : #{runner.edf.reserved.to_s.inspect}"
11
+ result
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ module Edfize
2
+ module Tests
3
+ module CheckReservedSignalAreas
4
+ # This test checks that the reserved areas in the signal headers are blank
5
+ def test_reserved_signal_areas_blank(runner)
6
+ reserved_areas = runner.edf.signals.collect(&:reserved_area)
7
+
8
+ result = Result.new
9
+ result.passes = (reserved_areas.reject{|r| r.to_s.strip == ''}.count == 0)
10
+ result.pass_fail = " #{result.passes ? 'PASS' : 'FAIL'}".colorize( result.passes ? :green : :red ) + " Signal Reserved Area Blank"
11
+ result.expected = " Expected : #{[''] * runner.edf.signals.count}"
12
+ result.actual = " Actual : #{reserved_areas}"
13
+ result
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,7 @@
1
+ module Edfize
2
+ module Tests
3
+ class Result
4
+ attr_accessor :passes, :pass_fail, :expected, :actual
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,54 @@
1
+ module Edfize
2
+ module Tests
3
+ class Runner
4
+ attr_reader :tests_run, :tests_failed, :edf, :verbose, :show_passing
5
+
6
+ TESTS = %w( expected_length reserved_area_blank reserved_signal_areas_blank )
7
+
8
+ def initialize(edf, argv)
9
+ @tests_run = 0
10
+ @tests_failed = 0
11
+ @edf = edf
12
+ @verbose = argv.include?('--quiet') ? false : true
13
+ @show_passing = argv.include?('--failing') ? false : true
14
+ end
15
+
16
+ def run_tests
17
+ results = []
18
+
19
+ TESTS.each do |test_name|
20
+ result = Edfize::Tests.send("test_#{test_name}", self)
21
+ @tests_failed += 1 unless result.passes
22
+ @tests_run += 1
23
+ results << result
24
+ end
25
+
26
+ puts "\n#{@edf.filename}" if results.reject{|r| r.passes}.count > 0 or @show_passing
27
+ results.each do |result|
28
+ print_result(result)
29
+ end
30
+
31
+ # test_expected_length(edf) ? nil : failure_count += 1
32
+ # test_count += 1
33
+
34
+ # test_reserved_area_blank(edf) ? nil : failure_count += 1
35
+ # test_count += 1
36
+
37
+ # test_reserved_signal_areas_blank(edf) ? nil : failure_count += 1
38
+ # test_count += 1
39
+
40
+ # [test_count, failure_count]
41
+ end
42
+
43
+ def print_result(result)
44
+ if self.show_passing or !result.passes
45
+ puts result.pass_fail
46
+ unless result.passes or not self.verbose
47
+ puts result.expected
48
+ puts result.actual
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
data/lib/edfize/tests.rb CHANGED
@@ -1,21 +1,13 @@
1
+ require 'edfize/tests/result'
2
+ require 'edfize/tests/runner'
1
3
  require 'edfize/tests/check_length'
4
+ require 'edfize/tests/check_reserved_area'
5
+ require 'edfize/tests/check_reserved_signal_areas'
2
6
 
3
7
  module Edfize
4
8
  module Tests
5
- def self.verbose
6
- true
7
- end
8
-
9
- def self.run(edf)
10
- puts "\n#{edf.filename}"
11
-
12
- failure_count = 0
13
- test_count = 0
14
-
15
- test_expected_length(edf) ? nil : failure_count += 1
16
- test_count += 1
17
-
18
- [test_count, failure_count]
19
- end
9
+ extend CheckLength
10
+ extend CheckReservedArea
11
+ extend CheckReservedSignalAreas
20
12
  end
21
13
  end
@@ -3,7 +3,7 @@ module Edfize
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
5
  TINY = 0
6
- BUILD = "beta1"
6
+ BUILD = "beta2"
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, BUILD].compact.join('.')
9
9
  end
data/lib/edfize.rb CHANGED
@@ -10,7 +10,7 @@ module Edfize
10
10
  when 'v'
11
11
  version
12
12
  when 'c', 't'
13
- check
13
+ check(argv[1..-1])
14
14
  when 'r'
15
15
  print_headers
16
16
  else
@@ -31,7 +31,7 @@ module Edfize
31
31
  puts "Edfize #{Edfize::VERSION::STRING}"
32
32
  end
33
33
 
34
- def self.check
34
+ def self.check(argv)
35
35
  test_start_time = Time.now
36
36
  edf_count = edfs_in_current_directory.count
37
37
  test_count = 0
@@ -39,9 +39,10 @@ module Edfize
39
39
  puts "Started\n"
40
40
  edfs_in_current_directory.each do |edf_file_name|
41
41
  edf = Edfize::Edf.new(edf_file_name)
42
- tests_run, failures = Edfize::Tests.run(edf)
43
- test_count += tests_run
44
- failure_count += failures
42
+ runner = Edfize::Tests::Runner.new(edf, argv)
43
+ runner.run_tests
44
+ test_count += runner.tests_run
45
+ failure_count += runner.tests_failed
45
46
  end
46
47
  puts "\nFinished in #{Time.now - test_start_time}s"
47
48
  puts "#{edf_count} EDF#{'s' unless edf_count == 1}, #{test_count} test#{'s' unless test_count == 1}, " + "#{failure_count} failure#{'s' unless failure_count == 1}".colorize( failure_count == 0 ? :green : :red )
@@ -54,6 +55,7 @@ Usage: edfize COMMAND [ARGS]
54
55
  The most common edfize commands are:
55
56
  [c]heck Check EDFs in current directory for errors
56
57
  [t]est Same as [c]heck
58
+ [r]un Print EDF headers for current directory
57
59
  [h]elp Show edfize command-line documentation
58
60
  [v]ersion Returns the version of Edfize
59
61
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: edfize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.beta1
4
+ version: 0.1.0.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Remo Mueller
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-30 00:00:00.000000000 Z
11
+ date: 2014-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -72,6 +72,10 @@ files:
72
72
  - lib/edfize/signal.rb
73
73
  - lib/edfize/tests.rb
74
74
  - lib/edfize/tests/check_length.rb
75
+ - lib/edfize/tests/check_reserved_area.rb
76
+ - lib/edfize/tests/check_reserved_signal_areas.rb
77
+ - lib/edfize/tests/result.rb
78
+ - lib/edfize/tests/runner.rb
75
79
  - lib/edfize/version.rb
76
80
  homepage: https://github.com/sleepepi/edfize
77
81
  licenses: