seis_ruby 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/seis_ruby/application.rb +4 -3
- data/lib/seis_ruby/data/sac/binary/head.rb +1 -1
- data/lib/seis_ruby/data/sac/head.rb +88 -74
- data/lib/seis_ruby/version.rb +1 -1
- data/test/seis_ruby/data/sac/head_test.rb +39 -45
- metadata +13 -38
@@ -3,6 +3,7 @@ require 'thor'
|
|
3
3
|
class ::SeisRuby::Application < Thor
|
4
4
|
require 'yaml'
|
5
5
|
require 'fileutils'
|
6
|
+
require 'ruby_patch'
|
6
7
|
|
7
8
|
COMMAND = 'seis_ruby'
|
8
9
|
COMPLETION_FILE = File.join(ENV['HOME'], ".config", COMMAND, "completion.bash")
|
@@ -12,10 +13,10 @@ class ::SeisRuby::Application < Thor
|
|
12
13
|
repl_hook()
|
13
14
|
|
14
15
|
Pry.start(
|
15
|
-
::
|
16
|
+
::SeisRuby,
|
16
17
|
prompt: [
|
17
|
-
lambda{|obj, nest_level, pry| "[#{pry.input_array.size}]
|
18
|
-
lambda{|obj, nest_level, pry| "[#{pry.input_array.size}]
|
18
|
+
lambda{|obj, nest_level, pry| "[#{pry.input_array.size}] #{obj}:#{nest_level}> "},
|
19
|
+
lambda{|obj, nest_level, pry| "[#{pry.input_array.size}] #{obj}:#{nest_level}* "}])
|
19
20
|
end
|
20
21
|
|
21
22
|
desc "yamlize URI", "Read data from URI, parse it and output to STDOUT in YAML format."
|
@@ -61,80 +61,94 @@ module ::SeisRuby::Data::Sac::Head
|
|
61
61
|
].map.with_index.with_object({}){|(v, i), h| h[i + 1] = v}
|
62
62
|
|
63
63
|
# Float
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
n
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
64
|
+
module FloatConverter
|
65
|
+
UNDEFINED = -12345.0
|
66
|
+
|
67
|
+
def self.from_head(x)
|
68
|
+
x_f = x.to_f
|
69
|
+
return nil if x_f == UNDEFINED
|
70
|
+
x_f
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.to_head(x)
|
74
|
+
return UNDEFINED if x.nil?
|
75
|
+
x.to_f
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
module IntegerConverter
|
80
|
+
UNDEFINED = -12345
|
81
|
+
|
82
|
+
def self.from_head(n)
|
83
|
+
n_i = n.to_f.round
|
84
|
+
return nil if n_i == UNDEFINED
|
85
|
+
n_i
|
86
|
+
end
|
87
|
+
|
88
|
+
def self.to_head(n)
|
89
|
+
return UNDEFINED if n.nil?
|
90
|
+
n.to_f.round
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
module EnumeratedValueConverter
|
95
|
+
UNDEFINED = -12345
|
96
|
+
|
97
|
+
def self.from_head(n)
|
98
|
+
n_i = n.to_f.round
|
99
|
+
return nil if n_i == UNDEFINED
|
100
|
+
raise ArgumentError, "Enumerated value out of range: #{n.inspect}.to_f.round" unless ENUMERATED_VALUES.has_key?(n_i)
|
101
|
+
ENUMERATED_VALUES.fetch(n_i)
|
102
|
+
end
|
103
|
+
|
104
|
+
def self.to_head(sym)
|
105
|
+
return UNDEFINED if sym.nil?
|
106
|
+
sym_sym = sym.to_sym
|
107
|
+
raise ArgumentError, "Unknown enumerated value: #{sym.inspect}.to_sym" unless ENUMERATED_VALUES.has_value?(sym_sym)
|
108
|
+
ENUMERATED_VALUES.key(sym_sym)
|
106
109
|
end
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
110
|
+
end
|
111
|
+
|
112
|
+
module LogicalConverter
|
113
|
+
def self.from_head(n)
|
114
|
+
n.to_f.round == 1
|
115
|
+
end
|
116
|
+
|
117
|
+
def self.to_head(v)
|
118
|
+
if v
|
119
|
+
1
|
120
|
+
else
|
121
|
+
0
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
module StringConverter
|
127
|
+
UNDEFINED = '-12345'
|
128
|
+
|
129
|
+
def self.from_head(str)
|
130
|
+
stripped_str = str.to_s.strip
|
131
|
+
return nil if stripped_str == UNDEFINED
|
132
|
+
stripped_str
|
133
|
+
end
|
134
|
+
|
135
|
+
def self.to_head(str)
|
136
|
+
return UNDEFINED if str.nil?
|
137
|
+
str.to_s.strip
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
CONVERTERS\
|
142
|
+
= [FloatConverter]*70\
|
143
|
+
+ [IntegerConverter]*15\
|
144
|
+
+ [EnumeratedValueConverter]*20\
|
145
|
+
+ [LogicalConverter]*5\
|
146
|
+
+ [StringConverter]*23
|
147
|
+
|
148
|
+
Field = Struct.new(:name, :converter)
|
135
149
|
FIELDS = NAMES\
|
136
|
-
.zip(
|
137
|
-
.map{|name,
|
150
|
+
.zip(CONVERTERS)\
|
151
|
+
.map{|name, converter| Field.new(name, converter)}
|
138
152
|
|
139
153
|
class << self
|
140
154
|
# @param [Array] array
|
@@ -144,7 +158,7 @@ module ::SeisRuby::Data::Sac::Head
|
|
144
158
|
.zip(array)\
|
145
159
|
.map{|field, val|
|
146
160
|
begin
|
147
|
-
[field.name, field.
|
161
|
+
[field.name, field.converter.from_head(val)]
|
148
162
|
rescue ArgumentError => e
|
149
163
|
$stderr.puts "Field name: #{field.name.inspect}"
|
150
164
|
raise e
|
@@ -156,7 +170,7 @@ module ::SeisRuby::Data::Sac::Head
|
|
156
170
|
# @param [Hash] hash
|
157
171
|
# @return [Array]
|
158
172
|
def convert_to_head(hash)
|
159
|
-
FIELDS.map{|field| field.
|
173
|
+
FIELDS.map{|field| field.converter.to_head(hash[field.name])}
|
160
174
|
end
|
161
175
|
end
|
162
176
|
end
|
data/lib/seis_ruby/version.rb
CHANGED
@@ -12,67 +12,61 @@ class HeadTest < ::MiniTest::Unit::TestCase
|
|
12
12
|
|
13
13
|
T = ::SeisRuby::Data::Sac::Head
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
F = T::FloatConverter
|
16
|
+
N = T::IntegerConverter
|
17
|
+
I = T::EnumeratedValueConverter
|
18
|
+
L = T::LogicalConverter
|
19
|
+
K = T::StringConverter
|
20
20
|
|
21
21
|
def test_convert_from_head_undefined
|
22
|
-
assert_nil(
|
23
|
-
assert_nil(
|
24
|
-
assert_nil(
|
25
|
-
assert_nil(
|
22
|
+
assert_nil(F.from_head(-12345.0))
|
23
|
+
assert_nil(N.from_head(-12345))
|
24
|
+
assert_nil(I.from_head(-12345))
|
25
|
+
assert_nil(K.from_head("-12345"))
|
26
26
|
end
|
27
27
|
|
28
28
|
def test_convert_from_head_valid
|
29
|
-
assert_equal(42.0,
|
30
|
-
assert_equal(42,
|
31
|
-
assert_equal(:itime,
|
32
|
-
assert_equal(:ipostq,
|
33
|
-
assert_equal(:iu,
|
34
|
-
assert_equal(true,
|
35
|
-
assert_equal(false,
|
36
|
-
assert_equal("42",
|
29
|
+
assert_equal(42.0, F.from_head(42.0))
|
30
|
+
assert_equal(42, N.from_head(42))
|
31
|
+
assert_equal(:itime, I.from_head(1))
|
32
|
+
assert_equal(:ipostq, I.from_head(42))
|
33
|
+
assert_equal(:iu, I.from_head(86))
|
34
|
+
assert_equal(true, L.from_head(1))
|
35
|
+
assert_equal(false, L.from_head(0))
|
36
|
+
assert_equal("42", K.from_head("42"))
|
37
37
|
end
|
38
38
|
|
39
39
|
def test_convert_from_head_invalid
|
40
|
-
assert_raises(ArgumentError, NoMethodError){
|
41
|
-
assert_raises(ArgumentError, NoMethodError){
|
42
|
-
assert_raises(ArgumentError, NoMethodError){
|
43
|
-
assert_raises(ArgumentError, NoMethodError){
|
44
|
-
assert_raises(ArgumentError, NoMethodError){
|
45
|
-
assert_raises(ArgumentError, NoMethodError){
|
40
|
+
assert_raises(ArgumentError, NoMethodError){F.from_head(:'1.0')}
|
41
|
+
assert_raises(ArgumentError, NoMethodError){N.from_head(:'1')}
|
42
|
+
assert_raises(ArgumentError, NoMethodError){I.from_head(-1)}
|
43
|
+
assert_raises(ArgumentError, NoMethodError){I.from_head(0)}
|
44
|
+
assert_raises(ArgumentError, NoMethodError){I.from_head(87)}
|
45
|
+
assert_raises(ArgumentError, NoMethodError){I.from_head(88)}
|
46
46
|
end
|
47
47
|
|
48
|
-
F_TO = T::CONVERTER_TO_HEAD_FLOAT
|
49
|
-
N_TO = T::CONVERTER_TO_HEAD_INTEGER
|
50
|
-
I_TO = T::CONVERTER_TO_HEAD_ENUMERATED_VALUE
|
51
|
-
L_TO = T::CONVERTER_TO_HEAD_LOGICAL
|
52
|
-
K_TO = T::CONVERTER_TO_HEAD_STRING
|
53
|
-
|
54
48
|
def test_convert_to_head_undefined
|
55
|
-
assert_equal(-12345.0,
|
56
|
-
assert_equal(-12345,
|
57
|
-
assert_equal(-12345,
|
58
|
-
assert_equal(0,
|
59
|
-
assert_equal("-12345",
|
49
|
+
assert_equal(-12345.0, F.to_head(nil))
|
50
|
+
assert_equal(-12345, N.to_head(nil))
|
51
|
+
assert_equal(-12345, I.to_head(nil))
|
52
|
+
assert_equal(0, L.to_head(nil))
|
53
|
+
assert_equal("-12345", K.to_head(nil))
|
60
54
|
end
|
61
55
|
|
62
56
|
def test_convert_to_head_valid
|
63
|
-
assert_equal(42.0,
|
64
|
-
assert_equal(42,
|
65
|
-
assert_equal(1,
|
66
|
-
assert_equal(42,
|
67
|
-
assert_equal(86,
|
68
|
-
assert_equal(1,
|
69
|
-
assert_equal(0,
|
70
|
-
assert_equal("42",
|
57
|
+
assert_equal(42.0, F.to_head(42.0))
|
58
|
+
assert_equal(42, N.to_head(42))
|
59
|
+
assert_equal(1, I.to_head(:itime))
|
60
|
+
assert_equal(42, I.to_head(:ipostq))
|
61
|
+
assert_equal(86, I.to_head(:iu))
|
62
|
+
assert_equal(1, L.to_head(true))
|
63
|
+
assert_equal(0, L.to_head(false))
|
64
|
+
assert_equal("42", K.to_head("42"))
|
71
65
|
end
|
72
66
|
|
73
67
|
def test_convert_to_head_invalid
|
74
|
-
assert_raises(ArgumentError, NoMethodError){
|
75
|
-
assert_raises(ArgumentError, NoMethodError){
|
76
|
-
assert_raises(ArgumentError, NoMethodError){
|
68
|
+
assert_raises(ArgumentError, NoMethodError){F.to_head(:"42.0")}
|
69
|
+
assert_raises(ArgumentError, NoMethodError){N.to_head(:"42")}
|
70
|
+
assert_raises(ArgumentError, NoMethodError){I.to_head(:this_is_not_exist)}
|
77
71
|
end
|
78
72
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seis_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: watchr
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirement: &2154938040 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,15 +21,10 @@ dependencies:
|
|
21
21
|
version: '0.7'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ~>
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '0.7'
|
24
|
+
version_requirements: *2154938040
|
30
25
|
- !ruby/object:Gem::Dependency
|
31
26
|
name: thor
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
27
|
+
requirement: &2154937560 !ruby/object:Gem::Requirement
|
33
28
|
none: false
|
34
29
|
requirements:
|
35
30
|
- - ~>
|
@@ -37,15 +32,10 @@ dependencies:
|
|
37
32
|
version: '0.15'
|
38
33
|
type: :runtime
|
39
34
|
prerelease: false
|
40
|
-
version_requirements:
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ~>
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: '0.15'
|
35
|
+
version_requirements: *2154937560
|
46
36
|
- !ruby/object:Gem::Dependency
|
47
37
|
name: mechanize
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
38
|
+
requirement: &2154937100 !ruby/object:Gem::Requirement
|
49
39
|
none: false
|
50
40
|
requirements:
|
51
41
|
- - ~>
|
@@ -53,15 +43,10 @@ dependencies:
|
|
53
43
|
version: '2.5'
|
54
44
|
type: :runtime
|
55
45
|
prerelease: false
|
56
|
-
version_requirements:
|
57
|
-
none: false
|
58
|
-
requirements:
|
59
|
-
- - ~>
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '2.5'
|
46
|
+
version_requirements: *2154937100
|
62
47
|
- !ruby/object:Gem::Dependency
|
63
48
|
name: pry
|
64
|
-
requirement: !ruby/object:Gem::Requirement
|
49
|
+
requirement: &2154936640 !ruby/object:Gem::Requirement
|
65
50
|
none: false
|
66
51
|
requirements:
|
67
52
|
- - ! '>='
|
@@ -69,15 +54,10 @@ dependencies:
|
|
69
54
|
version: 0.9.10
|
70
55
|
type: :runtime
|
71
56
|
prerelease: false
|
72
|
-
version_requirements:
|
73
|
-
none: false
|
74
|
-
requirements:
|
75
|
-
- - ! '>='
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
version: 0.9.10
|
57
|
+
version_requirements: *2154936640
|
78
58
|
- !ruby/object:Gem::Dependency
|
79
59
|
name: ruby_patch
|
80
|
-
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirement: &2154936180 !ruby/object:Gem::Requirement
|
81
61
|
none: false
|
82
62
|
requirements:
|
83
63
|
- - ! '>='
|
@@ -85,12 +65,7 @@ dependencies:
|
|
85
65
|
version: 1.1.0
|
86
66
|
type: :development
|
87
67
|
prerelease: false
|
88
|
-
version_requirements:
|
89
|
-
none: false
|
90
|
-
requirements:
|
91
|
-
- - ! '>='
|
92
|
-
- !ruby/object:Gem::Version
|
93
|
-
version: 1.1.0
|
68
|
+
version_requirements: *2154936180
|
94
69
|
description: Ruby library for earthquake science.
|
95
70
|
email:
|
96
71
|
executables:
|
@@ -166,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
166
141
|
version: '0'
|
167
142
|
requirements: []
|
168
143
|
rubyforge_project:
|
169
|
-
rubygems_version: 1.8.
|
144
|
+
rubygems_version: 1.8.15
|
170
145
|
signing_key:
|
171
146
|
specification_version: 3
|
172
147
|
summary: Ruby library for earthquake science.
|