text-data-tools 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/text-data-tools.rb +12 -12
- data/test/test_text-data-tools.rb +12 -12
- data/text-data-tools.gemspec +2 -2
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.5
|
data/lib/text-data-tools.rb
CHANGED
@@ -153,12 +153,12 @@ module TextDataTools
|
|
153
153
|
column_header = index_array.index(index_array.compact[0])
|
154
154
|
end
|
155
155
|
|
156
|
-
# This is a simple class which can interface with the methods of
|
156
|
+
# This is a simple class which can interface with the methods of TextDataTools
|
157
157
|
# to prevent the user having to specify the file name and other properties of the
|
158
158
|
# data file for every call. In a
|
159
159
|
# nutshell, create a new instance of this class giving it the filename, and any
|
160
160
|
# appropriate options,
|
161
|
-
# then call methods from
|
161
|
+
# then call methods from TextDataTools omitting the appropriate arguments.
|
162
162
|
class TextDataFile
|
163
163
|
def initialize(filename, has_header_line = false, match = /\S+/, header_match = /\S+/)
|
164
164
|
@filename = filename
|
@@ -168,32 +168,32 @@ module TextDataTools
|
|
168
168
|
self
|
169
169
|
end
|
170
170
|
def get_1d_array(column_header)
|
171
|
-
|
171
|
+
TextDataTools.get_1d_array(@filename, @has_header_line, column_header, @match, @header_match)
|
172
172
|
end
|
173
173
|
def get_1d_array_float(column_header)
|
174
|
-
|
174
|
+
TextDataTools.get_1d_array_float(@filename, @has_header_line, column_header, @match, @header_match)
|
175
175
|
end
|
176
176
|
def get_1d_array_integer(column_header)
|
177
|
-
|
177
|
+
TextDataTools.get_1d_array_integer(@filename, @has_header_line, column_header, @match, @header_match)
|
178
178
|
end
|
179
179
|
def get_2d_array(column_header, index_header)
|
180
|
-
|
180
|
+
TextDataTools.get_2d_array(@filename, @has_header_line, column_header, index_header, @match, @header_match)
|
181
181
|
end
|
182
182
|
def get_2d_array_float(column_header, index_header)
|
183
|
-
|
183
|
+
TextDataTools.get_2d_array(@filename, @has_header_line, column_header, index_header, @match, @header_match)
|
184
184
|
end
|
185
185
|
def get_2d_array_integer(column_header, index_header)
|
186
|
-
|
186
|
+
TextDataTools.get_2d_array(@filename, @has_header_line, column_header, index_header, @match, @header_match)
|
187
187
|
end
|
188
188
|
def get_variable_value(name, sep)
|
189
|
-
|
189
|
+
TextDataTools.get_variable_value(@filename, name, sep)
|
190
190
|
end
|
191
191
|
#def method_missing(meth, *args)
|
192
|
-
#if
|
193
|
-
#
|
192
|
+
#if TextDataTools.methods.include? meth
|
193
|
+
#TextDataTools.send(meth, @filename, *args)
|
194
194
|
#else
|
195
195
|
#super
|
196
196
|
#end
|
197
197
|
#end
|
198
198
|
end
|
199
|
-
end # module
|
199
|
+
end # module TextDataTools
|
@@ -1,22 +1,22 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class TestTextDataTools < Test::Unit::TestCase
|
4
4
|
def test_1d
|
5
|
-
assert_raise(ArgumentError){
|
6
|
-
assert_raise(ArgumentError){
|
7
|
-
array =
|
5
|
+
assert_raise(ArgumentError){TextDataTools.get_1d_array('test/test_dat.dat', true, 2.2)}
|
6
|
+
assert_raise(ArgumentError){TextDataTools.get_1d_array('test/test_dat.dat',true, /ii\+ temp/, /\S+/, /(?:\#\s+)?\d:.*?(?=\d:)/)}
|
7
|
+
array = TextDataTools.get_1d_array('test/test_dat.dat', true, /i\+ temp/, /\S+/, /(?:\#\s+)?\d:.*?(?=\d:)/)
|
8
8
|
#puts array
|
9
9
|
assert_equal(array.size, 18)
|
10
10
|
assert_equal(array[9].to_f, 0.9753E+09)
|
11
|
-
array =
|
11
|
+
array = TextDataTools.get_1d_array_float('test/test_dat.dat', true, /i\+ temp/, /\S+/, /(?:\#\s+)?\d:.*?(?=\d:)/)
|
12
12
|
assert_equal(array[9], 0.9753E+09)
|
13
13
|
end
|
14
14
|
def test_2d
|
15
|
-
array =
|
15
|
+
array = TextDataTools.get_2d_array('test/test_dat.dat', true, /i\+ temp/, 0, /\S+/, /(?:\#\s+)?\d:.*?(?=\d:)/)
|
16
16
|
assert_equal(array.size, 2)
|
17
|
-
array =
|
17
|
+
array = TextDataTools.get_2d_array('test/test_dat.dat', true, /i\+ temp/, 1, /\S+/, /(?:\#\s+)?\d:.*?(?=\d:)/)
|
18
18
|
assert_equal(array.size, 18)
|
19
|
-
array =
|
19
|
+
array = TextDataTools.get_2d_array_float('test/test_dat.dat', true, /i\+ temp/, 0, /\S+/, /(?:\#\s+)?\d:.*?(?=\d:)/)
|
20
20
|
assert_equal(array[0].size, 9)
|
21
21
|
assert_equal(array[1][0], 0.9753E+09)
|
22
22
|
|
@@ -24,15 +24,15 @@ class TestTextFileTools < Test::Unit::TestCase
|
|
24
24
|
|
25
25
|
end
|
26
26
|
def test_get_variable
|
27
|
-
variable =
|
27
|
+
variable = TextDataTools.get_variable_value('test/test_dat_2.dat', 'Q', ':')
|
28
28
|
assert_equal(variable.to_f, 11.989644168449118)
|
29
|
-
variable =
|
29
|
+
variable = TextDataTools.get_variable_value('test/test_dat_2.dat', 'Fusion power', ':')
|
30
30
|
assert_equal(variable.to_f, 484.34196189744871)
|
31
31
|
end
|
32
32
|
def test_texdatafile_class
|
33
|
-
file =
|
33
|
+
file = TextDataTools::TextDataFile.new('test/test_dat_2.dat')
|
34
34
|
assert_equal(file.get_variable_value('Alpha power', ':').to_f, 116.90499891894469 )
|
35
|
-
file =
|
35
|
+
file = TextDataTools::TextDataFile.new('test/test_dat.dat', true, /\S+/, /(?:\#\s+)?\d:.*?(?=\d:)/)
|
36
36
|
array = file.get_2d_array(/i\+ temp/, /1.*time/)
|
37
37
|
assert_equal(array.size, 2)
|
38
38
|
end
|
data/text-data-tools.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "text-data-tools"
|
8
|
-
s.version = "1.0.
|
8
|
+
s.version = "1.0.5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Edmund Highcock"]
|
12
|
-
s.date = "2013-06-
|
12
|
+
s.date = "2013-06-17"
|
13
13
|
s.description = "A small set of tools for reading text based data files into arrays. Works ee.g. for simple columnar data with or without headings."
|
14
14
|
s.email = "edmundhighcock@sourceforge.net"
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: text-data-tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
12
|
+
date: 2013-06-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: shoulda
|
@@ -111,7 +111,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
111
111
|
version: '0'
|
112
112
|
segments:
|
113
113
|
- 0
|
114
|
-
hash:
|
114
|
+
hash: 728842535758122685
|
115
115
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
116
|
none: false
|
117
117
|
requirements:
|