seis_ruby 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +2 -2
- data/lib/seis_ruby/application.rb +7 -2
- data/lib/seis_ruby/data/cmtsolution.rb +28 -28
- data/lib/seis_ruby/data/sac/head.rb +1 -1
- data/lib/seis_ruby/database/global_cmt_catalog_search/cmtsolution_format/custom_html_parser.rb +7 -0
- data/lib/seis_ruby/database/global_cmt_catalog_search/cmtsolution_format.rb +8 -7
- data/lib/seis_ruby/database/global_cmt_catalog_search.rb +11 -2
- data/lib/seis_ruby/version.rb +1 -1
- metadata +39 -13
data/README.rdoc
CHANGED
@@ -2,13 +2,13 @@
|
|
2
2
|
== What is this?
|
3
3
|
Ruby library and command line tools for earthquake science.
|
4
4
|
|
5
|
-
== Command
|
5
|
+
== Command Line Tool
|
6
6
|
seis_ruby help
|
7
7
|
|
8
8
|
== Library
|
9
9
|
Please check {SeisRuby::Command} which provides handy methods via {::SeisRuby}.
|
10
10
|
|
11
|
-
== Quick
|
11
|
+
== Quick Start
|
12
12
|
require 'seis_ruby'
|
13
13
|
sac = SeisRuby.load_file('test_read.SAC') # Read a SAC file
|
14
14
|
sac.head[:a] += 3.0 # Shift Tp 3.0 seconds
|
@@ -2,7 +2,6 @@ require 'thor'
|
|
2
2
|
|
3
3
|
class ::SeisRuby::Application < Thor
|
4
4
|
require 'yaml'
|
5
|
-
require 'pry'
|
6
5
|
require 'fileutils'
|
7
6
|
|
8
7
|
COMMAND = 'seis_ruby'
|
@@ -10,6 +9,8 @@ class ::SeisRuby::Application < Thor
|
|
10
9
|
|
11
10
|
desc "repl", "Start interactive mode."
|
12
11
|
def repl
|
12
|
+
repl_hook()
|
13
|
+
|
13
14
|
Pry.start(
|
14
15
|
::TOPLEVEL_BINDING,
|
15
16
|
prompt: [
|
@@ -26,7 +27,7 @@ class ::SeisRuby::Application < Thor
|
|
26
27
|
def generate_completion
|
27
28
|
FileUtils.mkdir_p(File.dirname(COMPLETION_FILE))
|
28
29
|
FileUtils.mv(COMPLETION_FILE, "#{COMPLETION_FILE}.#{Time.now.ymdhms}.bak") if File.exist?(COMPLETION_FILE)
|
29
|
-
File.write(COMPLETION_FILE, completion_function_str)
|
30
|
+
File.write(COMPLETION_FILE, completion_function_str())
|
30
31
|
|
31
32
|
puts <<-EOS
|
32
33
|
Please add following code to your ~/.bashrc if necessary.
|
@@ -45,6 +46,10 @@ fi
|
|
45
46
|
|
46
47
|
private
|
47
48
|
|
49
|
+
def repl_hook
|
50
|
+
require 'pry'
|
51
|
+
end
|
52
|
+
|
48
53
|
def completion_function_str
|
49
54
|
<<-EOS
|
50
55
|
_#{COMMAND}()
|
@@ -1,34 +1,6 @@
|
|
1
1
|
class ::SeisRuby::Data::Cmtsolution < ::SeisRuby::Data
|
2
2
|
require 'ostruct'
|
3
3
|
|
4
|
-
def self.load_file(file)
|
5
|
-
load(File.read_uri(file), file: file)
|
6
|
-
end
|
7
|
-
|
8
|
-
def self.load(raw_data, meta_data)
|
9
|
-
new(raw_data, meta_data)
|
10
|
-
end
|
11
|
-
|
12
|
-
def initialize(raw_data, meta_data)
|
13
|
-
@raw_data = raw_data
|
14
|
-
@meta_data = meta_data
|
15
|
-
parse!
|
16
|
-
end
|
17
|
-
attr_accessor :hypocenter
|
18
|
-
attr_accessor :centroid
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
def parse!
|
23
|
-
lines\
|
24
|
-
= @raw_data\
|
25
|
-
.split("\n")\
|
26
|
-
.map(&:strip)\
|
27
|
-
.delete_if(&:empty?)
|
28
|
-
@hypocenter = Hypocenter.new(lines[0])
|
29
|
-
@centroid = Centroid.new(lines[1..-1])
|
30
|
-
end
|
31
|
-
|
32
4
|
class Hypocenter < OpenStruct
|
33
5
|
FIELDS = [
|
34
6
|
# name, column, converter
|
@@ -94,4 +66,32 @@ class ::SeisRuby::Data::Cmtsolution < ::SeisRuby::Data
|
|
94
66
|
end
|
95
67
|
attr_accessor :table
|
96
68
|
end
|
69
|
+
|
70
|
+
def self.load_file(file)
|
71
|
+
load(File.read_uri(file), file: file)
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.load(raw_data, meta_data)
|
75
|
+
new(raw_data, meta_data)
|
76
|
+
end
|
77
|
+
|
78
|
+
def initialize(raw_data, meta_data)
|
79
|
+
@raw_data = raw_data
|
80
|
+
@meta_data = meta_data
|
81
|
+
parse!
|
82
|
+
end
|
83
|
+
attr_accessor :hypocenter
|
84
|
+
attr_accessor :centroid
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
def parse!
|
89
|
+
lines\
|
90
|
+
= @raw_data\
|
91
|
+
.split("\n")\
|
92
|
+
.map(&:strip)\
|
93
|
+
.delete_if(&:empty?)
|
94
|
+
@hypocenter = Hypocenter.new(lines[0])
|
95
|
+
@centroid = Centroid.new(lines[1..-1])
|
96
|
+
end
|
97
97
|
end
|
data/lib/seis_ruby/database/global_cmt_catalog_search/cmtsolution_format/custom_html_parser.rb
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
require 'mechanize'
|
2
|
+
|
3
|
+
class ::SeisRuby::Database::GlobalCmtCatalogSearch::CmtsolutionFormat::CustomHtmlParser < ::Mechanize::Page
|
4
|
+
def initialize(uri = nil, response = nil, body = nil, code = nil, mech = nil)
|
5
|
+
super(uri, response, body.gsub(/<=/, '<='), code, mech)
|
6
|
+
end
|
7
|
+
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
module ::SeisRuby::Database::GlobalCmtCatalogSearch::CmtsolutionFormat
|
2
|
-
require 'mechanize'
|
3
|
-
|
4
2
|
class << self
|
5
3
|
def load_file(uri)
|
4
|
+
load_file_hook()
|
5
|
+
|
6
6
|
agent = Mechanize.new{|a|
|
7
|
-
a.pluggable_parser.html = CustomHtmlParser
|
7
|
+
a.pluggable_parser.html = ::SeisRuby::Database::GlobalCmtCatalogSearch::CmtsolutionFormat::CustomHtmlParser
|
8
8
|
}
|
9
9
|
agent.get(uri)
|
10
10
|
|
@@ -20,11 +20,12 @@ module ::SeisRuby::Database::GlobalCmtCatalogSearch::CmtsolutionFormat
|
|
20
20
|
end
|
21
21
|
events.concat(load_file(next_link.uri))
|
22
22
|
end
|
23
|
-
end
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
private
|
25
|
+
|
26
|
+
def load_file_hook
|
27
|
+
require 'mechanize'
|
28
|
+
require 'seis_ruby/database/global_cmt_catalog_search/cmtsolution_format/custom_html_parser'
|
28
29
|
end
|
29
30
|
end
|
30
31
|
end
|
@@ -16,12 +16,16 @@ module ::SeisRuby::Database::GlobalCmtCatalogSearch
|
|
16
16
|
# @param [String] uri URI of a first page of Global CMT Catalog Search result.
|
17
17
|
# @return [Array<Hash>] {::SeisRuby::Data::Cmtsolution#parse}
|
18
18
|
def load_file(uri)
|
19
|
-
raise ArgumentError, "Not a URI of #{self}: #{uri}" unless uri
|
20
|
-
|
19
|
+
raise ArgumentError, "Not a URI of #{self}: #{uri}" unless uri_for_self?(uri)
|
20
|
+
module_from_uri(uri).load_file(uri)
|
21
21
|
end
|
22
22
|
|
23
23
|
private
|
24
24
|
|
25
|
+
def module_from_uri(uri)
|
26
|
+
module_from_list_number(list_number_from_uri(uri))
|
27
|
+
end
|
28
|
+
|
25
29
|
def module_from_list_number(list_number)
|
26
30
|
case list_number
|
27
31
|
when 0
|
@@ -40,5 +44,10 @@ module ::SeisRuby::Database::GlobalCmtCatalogSearch
|
|
40
44
|
raise ArgumentError, "Unsupported list number: #{list_number}"
|
41
45
|
end
|
42
46
|
end
|
47
|
+
|
48
|
+
def list_number_from_uri(uri)
|
49
|
+
uri =~ URI_FOR_SELF_REG
|
50
|
+
Regexp.last_match(1).to_i
|
51
|
+
end
|
43
52
|
end
|
44
53
|
end
|
data/lib/seis_ruby/version.rb
CHANGED
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.3
|
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-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: watchr
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: '0.7'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.7'
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: thor
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ~>
|
@@ -32,10 +37,15 @@ dependencies:
|
|
32
37
|
version: '0.15'
|
33
38
|
type: :runtime
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0.15'
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: mechanize
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
51
|
- - ~>
|
@@ -43,10 +53,15 @@ dependencies:
|
|
43
53
|
version: '2.5'
|
44
54
|
type: :runtime
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.5'
|
47
62
|
- !ruby/object:Gem::Dependency
|
48
63
|
name: pry
|
49
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
50
65
|
none: false
|
51
66
|
requirements:
|
52
67
|
- - ! '>='
|
@@ -54,10 +69,15 @@ dependencies:
|
|
54
69
|
version: 0.9.10
|
55
70
|
type: :runtime
|
56
71
|
prerelease: false
|
57
|
-
version_requirements:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 0.9.10
|
58
78
|
- !ruby/object:Gem::Dependency
|
59
79
|
name: ruby_patch
|
60
|
-
requirement:
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
61
81
|
none: false
|
62
82
|
requirements:
|
63
83
|
- - ! '>='
|
@@ -65,7 +85,12 @@ dependencies:
|
|
65
85
|
version: 1.1.0
|
66
86
|
type: :development
|
67
87
|
prerelease: false
|
68
|
-
version_requirements:
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 1.1.0
|
69
94
|
description: Ruby library for earthquake science.
|
70
95
|
email:
|
71
96
|
executables:
|
@@ -93,6 +118,7 @@ files:
|
|
93
118
|
- lib/seis_ruby/database.rb
|
94
119
|
- lib/seis_ruby/database/global_cmt_catalog_search.rb
|
95
120
|
- lib/seis_ruby/database/global_cmt_catalog_search/cmtsolution_format.rb
|
121
|
+
- lib/seis_ruby/database/global_cmt_catalog_search/cmtsolution_format/custom_html_parser.rb
|
96
122
|
- lib/seis_ruby/version.rb
|
97
123
|
- seis_ruby.gemspec
|
98
124
|
- test.watchr
|
@@ -140,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
166
|
version: '0'
|
141
167
|
requirements: []
|
142
168
|
rubyforge_project:
|
143
|
-
rubygems_version: 1.8.
|
169
|
+
rubygems_version: 1.8.23
|
144
170
|
signing_key:
|
145
171
|
specification_version: 3
|
146
172
|
summary: Ruby library for earthquake science.
|