seis_ruby 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/README.rdoc +23 -4
  2. data/Rakefile +10 -0
  3. data/bin/seis_ruby +1 -1
  4. data/lib/seis_ruby/application.rb +76 -0
  5. data/lib/seis_ruby/command.rb +15 -0
  6. data/lib/seis_ruby/core_ext/file.rb +7 -0
  7. data/lib/seis_ruby/core_ext.rb +5 -0
  8. data/lib/seis_ruby/data/cmtsolution.rb +84 -64
  9. data/lib/seis_ruby/data/sac/ascii/head.rb +49 -0
  10. data/lib/seis_ruby/data/sac/ascii.rb +61 -0
  11. data/lib/seis_ruby/data/sac/binary/head.rb +5 -0
  12. data/lib/seis_ruby/data/sac/binary.rb +26 -0
  13. data/lib/seis_ruby/data/sac/body.rb +62 -0
  14. data/lib/seis_ruby/data/sac/head.rb +162 -0
  15. data/lib/seis_ruby/data/sac.rb +99 -3
  16. data/lib/seis_ruby/data.rb +6 -5
  17. data/lib/seis_ruby/database/global_cmt_catalog_search/cmtsolution_format.rb +30 -0
  18. data/lib/seis_ruby/database/global_cmt_catalog_search.rb +44 -0
  19. data/lib/seis_ruby/database.rb +3 -0
  20. data/lib/seis_ruby/version.rb +1 -1
  21. data/lib/seis_ruby.rb +12 -3
  22. data/seis_ruby.gemspec +8 -14
  23. data/test/data/000000001.SAC +0 -0
  24. data/test/data/000000001.SAC_ascii +32 -0
  25. data/test/seis_ruby/command_test.rb +19 -0
  26. data/test/seis_ruby/core_ext/file_test.rb +7 -0
  27. data/test/seis_ruby/data/cmtsolution_test.rb +63 -0
  28. data/test/seis_ruby/data/sac/ascii_test.rb +15 -0
  29. data/test/seis_ruby/data/sac/binary_test.rb +15 -0
  30. data/test/seis_ruby/data/sac/body_test.rb +27 -0
  31. data/test/seis_ruby/data/sac/head_test.rb +78 -0
  32. data/test/seis_ruby/data/sac_test.rb +52 -0
  33. data/test/seis_ruby/database/global_cmt_catalog_search/cmtsolution_format_test.rb +142 -0
  34. data/test/seis_ruby/database/global_cmt_catalog_search_test.rb +10 -0
  35. data/test/seis_ruby_test.rb +0 -0
  36. data/test/test_helper.rb +7 -0
  37. data/test.watchr +13 -0
  38. metadata +79 -54
  39. data/lib/seis_ruby/bin/seis_ruby_runner.rb +0 -58
  40. data/lib/seis_ruby/bin.rb +0 -6
  41. data/lib/seis_ruby/io/gcmt_catalog/custom_html_parser.rb +0 -16
  42. data/lib/seis_ruby/io/gcmt_catalog.rb +0 -50
  43. data/lib/seis_ruby/io.rb +0 -6
  44. data/rakefile +0 -8
  45. data/spec/seis_ruby/data/cmtsolution_spec.rb +0 -83
  46. data/spec/seis_ruby/io/gcmt_catalog_spec.rb +0 -19
  47. data/spec/seis_ruby/io/scrape.yaml +0 -3972
  48. data/spec/spec_helper.rb +0 -18
@@ -0,0 +1,142 @@
1
+ require 'test_helper'
2
+
3
+ class CmtsolutionFormatTest < ::MiniTest::Unit::TestCase
4
+ T = ::SeisRuby::Database::GlobalCmtCatalogSearch::CmtsolutionFormat
5
+ URI = 'http://www.globalcmt.org/cgi-bin/globalcmt-cgi-bin/CMT4/form?itype=ymd&yr=1976&mo=1&day=1&oyr=1976&omo=1&oday=1&jyr=1976&jday=1&ojyr=1&ojday=1&otype=nd&nday=400&lmw=0&umw=10&lms=0&ums=10&lmb=0&umb=10&llat=-90&ulat=90&llon=-180&ulon=180&lhd=0&uhd=1000&lts=-9999&uts=9999&lpe1=0&upe1=90&lpe2=0&upe2=90&list=4'
6
+
7
+ def setup
8
+ @events = T.load_file(URI)
9
+ end
10
+
11
+ def test_load_file_result_size
12
+ assert_equal(147, @events.size)
13
+ end
14
+
15
+ def test_load_file_
16
+ end
17
+
18
+ def test_load_file_result_split
19
+ event_first_str = <<-EOS
20
+ MLI 1976 1 1 1 29 39.60 -28.6100 -177.6400 59.0 6.2 0.0 KERMADEC ISLANDS REGION
21
+ event name: 010176A
22
+ time shift: 13.8000
23
+ half duration: 9.4000
24
+ latitude: -29.2500
25
+ longitude: -176.9600
26
+ depth: 47.8000
27
+ Mrr: 7.680000e+26
28
+ Mtt: 9.000000e+24
29
+ Mpp: -7.770000e+26
30
+ Mrt: 1.390000e+26
31
+ Mrp: 4.520000e+26
32
+ Mtp: -3.260000e+26
33
+ EOS
34
+
35
+ event2_str = <<-EOS
36
+ MLI 1976 1 5 2 31 36.30 -13.2900 -74.9000 95.0 6.0 0.0 PERU
37
+ event name: 010576A
38
+ time shift: 8.4000
39
+ half duration: 1.6000
40
+ latitude: -13.4200
41
+ longitude: -75.1400
42
+ depth: 85.4000
43
+ Mrr: -1.780000e+24
44
+ Mtt: -5.900000e+23
45
+ Mpp: 2.370000e+24
46
+ Mrt: -1.280000e+24
47
+ Mrp: 1.970000e+24
48
+ Mtp: -2.900000e+24
49
+ EOS
50
+
51
+ event_last_of_the_first_page_str = <<-EOS
52
+ MLI 1976 11 18 5 43 41.30 -4.1700 135.1400 33.0 5.8 6.3 WEST IRIAN REGION
53
+ event name: 111876B
54
+ time shift: 4.4000
55
+ half duration: 4.2000
56
+ latitude: -4.1700
57
+ longitude: 134.9300
58
+ depth: 15.0000
59
+ Mrr: 7.900000e+24
60
+ Mtt: -1.480000e+25
61
+ Mpp: 6.900000e+24
62
+ Mrt: 2.240000e+25
63
+ Mrp: -5.630000e+25
64
+ Mtp: 1.870000e+25
65
+ EOS
66
+
67
+ event_first_of_the_2nd_page_str = <<-EOS
68
+ MLI 1976 11 22 4 22 25.30 7.0300 123.5800 60.0 6.0 0.0 MINDANAO, PHILIPPINE ISL
69
+ event name: 112276A
70
+ time shift: -4.6000
71
+ half duration: 3.0000
72
+ latitude: 7.0300
73
+ longitude: 123.5800
74
+ depth: 60.0000
75
+ Mrr: 2.030000e+23
76
+ Mtt: 4.260000e+23
77
+ Mpp: -6.290000e+23
78
+ Mrt: 1.780000e+23
79
+ Mrp: 2.020000e+23
80
+ Mtp: 2.200000e+22
81
+ EOS
82
+
83
+ event2_of_the_2nd_page_str = <<-EOS
84
+ MLI 1976 11 22 4 46 26.00 -38.5200 78.5700 33.0 5.5 6.0 MID-INDIAN RISE
85
+ event name: 112276B
86
+ time shift: 0.7000
87
+ half duration: 2.0000
88
+ latitude: -38.4000
89
+ longitude: 78.1200
90
+ depth: 15.0000
91
+ Mrr: -2.230000e+24
92
+ Mtt: -5.000000e+24
93
+ Mpp: 7.240000e+24
94
+ Mrt: 0.000000e+00
95
+ Mrp: 0.000000e+00
96
+ Mtp: -1.330000e+24
97
+ EOS
98
+
99
+ event_last_str = <<-EOS
100
+ MLI 1977 2 3 21 31 48.90 42.9700 130.9300 506.0 5.0 0.0 E USSR/NE CHINA BORDER
101
+ event name: 020377B
102
+ time shift: 7.5000
103
+ half duration: 1.5000
104
+ latitude: 42.5900
105
+ longitude: 130.4900
106
+ depth: 504.7000
107
+ Mrr: 8.730000e+22
108
+ Mtt: 5.023000e+23
109
+ Mpp: -5.896000e+23
110
+ Mrt: 2.772000e+23
111
+ Mrp: -3.293000e+23
112
+ Mtp: -1.860000e+23
113
+ EOS
114
+
115
+ s_d_c = ::SeisRuby::Data::Cmtsolution
116
+
117
+ event_first = s_d_c.load(event_first_str, {file: URI})
118
+ assert_equal(event_first.hypocenter, @events.first.hypocenter)
119
+ assert_equal(event_first.centroid, @events.first.centroid)
120
+
121
+ event2 = s_d_c.load(event2_str, {file: URI})
122
+ assert_equal(event2.hypocenter, @events[1].hypocenter)
123
+ assert_equal(event2.centroid, @events[1].centroid)
124
+
125
+ event_last_of_the_first_page = s_d_c.load(event_last_of_the_first_page_str, {file: URI})
126
+ assert_equal(event_last_of_the_first_page.hypocenter, @events[98].hypocenter)
127
+ assert_equal(event_last_of_the_first_page.centroid, @events[98].centroid)
128
+
129
+ uri_2nd_page = 'http://www.ldeo.columbia.edu/cgi-bin/globalcmt-cgi-bin/CMT3/form?itype=ymd&yr=1976&mo=1&day=1&oyr=1976&omo=1&oday=1&jyr=1976&jday=1&ojyr=1&ojday=1&otype=nd&nday=400&lmw=0&umw=10&lms=0&ums=10&lmb=0&umb=10&llat=-90&ulat=90&llon=-180&ulon=180&lhd=0&uhd=1000&lts=-9999&uts=9999&lpe1=0&upe1=90&lpe2=0&upe2=90&list=4&start=99'
130
+ event_first_of_the_2nd_page = s_d_c.load(event_first_of_the_2nd_page_str, {file: uri_2nd_page})
131
+ assert_equal(event_first_of_the_2nd_page.hypocenter, @events[99].hypocenter)
132
+ assert_equal(event_first_of_the_2nd_page.centroid, @events[99].centroid)
133
+
134
+ event2_of_the_2nd_page = s_d_c.load(event2_of_the_2nd_page_str, {file: uri_2nd_page})
135
+ assert_equal(event2_of_the_2nd_page.hypocenter, @events[100].hypocenter)
136
+ assert_equal(event2_of_the_2nd_page.centroid, @events[100].centroid)
137
+
138
+ event_last = s_d_c.load(event_last_str, {file: uri_2nd_page})
139
+ assert_equal(event_last.hypocenter, @events.last.hypocenter)
140
+ assert_equal(event_last.centroid, @events.last.centroid)
141
+ end
142
+ end
@@ -0,0 +1,10 @@
1
+ require 'test_helper'
2
+
3
+ class GlobalCmtCatalogSearchTest < ::MiniTest::Unit::TestCase
4
+ T = ::SeisRuby::Database::GlobalCmtCatalogSearch
5
+
6
+ def test_load_file_cmtsolution
7
+ events = T.load_file('http://www.globalcmt.org/cgi-bin/globalcmt-cgi-bin/CMT4/form?itype=ymd&yr=1976&mo=1&day=1&oyr=1976&omo=1&oday=1&jyr=1976&jday=1&ojyr=1&ojday=1&otype=nd&nday=400&lmw=0&umw=10&lms=0&ums=10&lmb=0&umb=10&llat=-90&ulat=90&llon=-180&ulon=180&lhd=0&uhd=1000&lts=-9999&uts=9999&lpe1=0&upe1=90&lpe2=0&upe2=90&list=4')
8
+ assert_equal(147, events.size)
9
+ end
10
+ end
File without changes
@@ -0,0 +1,7 @@
1
+ require 'minitest/pride'
2
+ require 'minitest/autorun'
3
+ require 'ruby_patch'
4
+
5
+ require 'seis_ruby'
6
+
7
+ TEST_DATA_DIR = File.join(__DIR__, 'data')
data/test.watchr ADDED
@@ -0,0 +1,13 @@
1
+ require 'fileutils'
2
+
3
+ RUBY = "ruby1.9"
4
+ watch("^test/(.*_test)\.rb"){|name| system "#{RUBY} -e '' -r #{name[1]} -I lib -I test"}
5
+ watch("^lib/(.*)\.rb"){|name|
6
+ test_file = "./test/#{name[1]}_test.rb"
7
+ unless File.readable?(test_file)
8
+ puts "Create #{test_file}"
9
+ FileUtils.mkdir_p(File.dirname(test_file))
10
+ FileUtils.touch(test_file)
11
+ end
12
+ system "#{RUBY} -e '' -r #{test_file} -I lib -I test"
13
+ }
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.1.2
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,76 +9,64 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-18 00:00:00.000000000 Z
12
+ date: 2012-12-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: rspec
16
- requirement: &2157288320 !ruby/object:Gem::Requirement
15
+ name: watchr
16
+ requirement: &2153803740 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: '2.10'
21
+ version: '0.7'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2157288320
24
+ version_requirements: *2153803740
25
25
  - !ruby/object:Gem::Dependency
26
- name: simplecov
27
- requirement: &2157287780 !ruby/object:Gem::Requirement
28
- none: false
29
- requirements:
30
- - - ~>
31
- - !ruby/object:Gem::Version
32
- version: '0.6'
33
- type: :development
34
- prerelease: false
35
- version_requirements: *2157287780
36
- - !ruby/object:Gem::Dependency
37
- name: rainbow
38
- requirement: &2157287220 !ruby/object:Gem::Requirement
26
+ name: thor
27
+ requirement: &2153802700 !ruby/object:Gem::Requirement
39
28
  none: false
40
29
  requirements:
41
30
  - - ~>
42
31
  - !ruby/object:Gem::Version
43
- version: '1.1'
32
+ version: '0.15'
44
33
  type: :runtime
45
34
  prerelease: false
46
- version_requirements: *2157287220
35
+ version_requirements: *2153802700
47
36
  - !ruby/object:Gem::Dependency
48
- name: thor
49
- requirement: &2157286720 !ruby/object:Gem::Requirement
37
+ name: mechanize
38
+ requirement: &2153801720 !ruby/object:Gem::Requirement
50
39
  none: false
51
40
  requirements:
52
41
  - - ~>
53
42
  - !ruby/object:Gem::Version
54
- version: '0.15'
43
+ version: '2.5'
55
44
  type: :runtime
56
45
  prerelease: false
57
- version_requirements: *2157286720
46
+ version_requirements: *2153801720
58
47
  - !ruby/object:Gem::Dependency
59
- name: mechanize
60
- requirement: &2157286060 !ruby/object:Gem::Requirement
48
+ name: pry
49
+ requirement: &2153800740 !ruby/object:Gem::Requirement
61
50
  none: false
62
51
  requirements:
63
- - - ~>
52
+ - - ! '>='
64
53
  - !ruby/object:Gem::Version
65
- version: '2.5'
66
- type: :runtime
54
+ version: 0.9.10
55
+ type: :development
67
56
  prerelease: false
68
- version_requirements: *2157286060
57
+ version_requirements: *2153800740
69
58
  - !ruby/object:Gem::Dependency
70
59
  name: ruby_patch
71
- requirement: &2157285180 !ruby/object:Gem::Requirement
60
+ requirement: &2153799980 !ruby/object:Gem::Requirement
72
61
  none: false
73
62
  requirements:
74
- - - ~>
63
+ - - ! '>='
75
64
  - !ruby/object:Gem::Version
76
- version: '1.1'
77
- type: :runtime
65
+ version: 1.1.0
66
+ type: :development
78
67
  prerelease: false
79
- version_requirements: *2157285180
80
- description: Ruby library for earthquake science. Provides Parser for various data
81
- formats used in seismology.
68
+ version_requirements: *2153799980
69
+ description: Ruby library for earthquake science.
82
70
  email:
83
71
  executables:
84
72
  - seis_ruby
@@ -86,36 +74,64 @@ extensions: []
86
74
  extra_rdoc_files: []
87
75
  files:
88
76
  - README.rdoc
77
+ - Rakefile
89
78
  - bin/seis_ruby
90
79
  - lib/seis_ruby.rb
91
- - lib/seis_ruby/bin.rb
92
- - lib/seis_ruby/bin/seis_ruby_runner.rb
80
+ - lib/seis_ruby/application.rb
81
+ - lib/seis_ruby/command.rb
82
+ - lib/seis_ruby/core_ext.rb
83
+ - lib/seis_ruby/core_ext/file.rb
93
84
  - lib/seis_ruby/data.rb
94
85
  - lib/seis_ruby/data/cmtsolution.rb
95
86
  - lib/seis_ruby/data/sac.rb
96
- - lib/seis_ruby/io.rb
97
- - lib/seis_ruby/io/gcmt_catalog.rb
98
- - lib/seis_ruby/io/gcmt_catalog/custom_html_parser.rb
87
+ - lib/seis_ruby/data/sac/ascii.rb
88
+ - lib/seis_ruby/data/sac/ascii/head.rb
89
+ - lib/seis_ruby/data/sac/binary.rb
90
+ - lib/seis_ruby/data/sac/binary/head.rb
91
+ - lib/seis_ruby/data/sac/body.rb
92
+ - lib/seis_ruby/data/sac/head.rb
93
+ - lib/seis_ruby/database.rb
94
+ - lib/seis_ruby/database/global_cmt_catalog_search.rb
95
+ - lib/seis_ruby/database/global_cmt_catalog_search/cmtsolution_format.rb
99
96
  - lib/seis_ruby/version.rb
100
- - rakefile
101
97
  - seis_ruby.gemspec
102
- - spec/seis_ruby/data/cmtsolution_spec.rb
103
- - spec/seis_ruby/io/gcmt_catalog_spec.rb
104
- - spec/seis_ruby/io/scrape.yaml
105
- - spec/spec_helper.rb
98
+ - test.watchr
99
+ - test/data/000000001.SAC
100
+ - test/data/000000001.SAC_ascii
101
+ - test/seis_ruby/command_test.rb
102
+ - test/seis_ruby/core_ext/file_test.rb
103
+ - test/seis_ruby/data/cmtsolution_test.rb
104
+ - test/seis_ruby/data/sac/ascii_test.rb
105
+ - test/seis_ruby/data/sac/binary_test.rb
106
+ - test/seis_ruby/data/sac/body_test.rb
107
+ - test/seis_ruby/data/sac/head_test.rb
108
+ - test/seis_ruby/data/sac_test.rb
109
+ - test/seis_ruby/database/global_cmt_catalog_search/cmtsolution_format_test.rb
110
+ - test/seis_ruby/database/global_cmt_catalog_search_test.rb
111
+ - test/seis_ruby_test.rb
112
+ - test/test_helper.rb
106
113
  homepage:
107
114
  licenses: []
108
- post_install_message: ! "\e[32m\n\nSeisRuby 0.1.2\nThank you for installing.\nPlease
109
- execute following command:\n\nseis_ruby generate_completion\n\nEnjoy!\n\n\n\e[0m"
115
+ post_install_message: ! '
116
+
117
+
118
+ Please execute following command:
119
+
120
+
121
+ seis_ruby generate_completion
122
+
123
+
124
+
125
+ '
110
126
  rdoc_options: []
111
127
  require_paths:
112
128
  - lib
113
129
  required_ruby_version: !ruby/object:Gem::Requirement
114
130
  none: false
115
131
  requirements:
116
- - - ~>
132
+ - - ! '>='
117
133
  - !ruby/object:Gem::Version
118
- version: '1.9'
134
+ version: 1.9.3
119
135
  required_rubygems_version: !ruby/object:Gem::Requirement
120
136
  none: false
121
137
  requirements:
@@ -129,6 +145,15 @@ signing_key:
129
145
  specification_version: 3
130
146
  summary: Ruby library for earthquake science.
131
147
  test_files:
132
- - spec/seis_ruby/data/cmtsolution_spec.rb
133
- - spec/seis_ruby/io/gcmt_catalog_spec.rb
148
+ - test/seis_ruby/command_test.rb
149
+ - test/seis_ruby/core_ext/file_test.rb
150
+ - test/seis_ruby/data/cmtsolution_test.rb
151
+ - test/seis_ruby/data/sac/ascii_test.rb
152
+ - test/seis_ruby/data/sac/binary_test.rb
153
+ - test/seis_ruby/data/sac/body_test.rb
154
+ - test/seis_ruby/data/sac/head_test.rb
155
+ - test/seis_ruby/data/sac_test.rb
156
+ - test/seis_ruby/database/global_cmt_catalog_search/cmtsolution_format_test.rb
157
+ - test/seis_ruby/database/global_cmt_catalog_search_test.rb
158
+ - test/seis_ruby_test.rb
134
159
  has_rdoc:
@@ -1,58 +0,0 @@
1
- module SeisRuby
2
- module Bin
3
- require 'thor'
4
-
5
- class SeisRubyRunner < Thor
6
- require 'yaml'
7
- require 'fileutils'
8
- require 'ruby_patch'
9
- extend ::RubyPatch::AutoLoad
10
-
11
- COMMAND_NAME = 'seis_ruby'
12
-
13
- desc 'gcmt_catalog_scrape URL', 'scrape cmtsolution data from GCMT catalog search result pages.'
14
- def gcmt_catalog_scrape(url)
15
- file = "#{__METHOD__}_#{Time.now.ymdhms}.yaml"
16
- open(file, 'w').write(SeisRuby::Io::GcmtCatalog.scrape(url).to_yaml)
17
- puts file
18
- end
19
-
20
- desc "generate_completion", "Generate bash completion of seis_ruby's commands."
21
- def generate_completion
22
- commands = `#{COMMAND_NAME} --help`.split("\n").select{|l| l =~ / *#{COMMAND_NAME} /}.map{|l| l.split[1]}
23
- function = <<-EOS
24
- _#{COMMAND_NAME}()
25
- {
26
- local commands current previous
27
- commands="#{commands.join(' ')}"
28
- current="${COMP_WORDS[COMP_CWORD]}"
29
- previous="${COMP_WORDS[COMP_CWORD-1]}"
30
-
31
- case "${previous}" in
32
- #{COMMAND_NAME}|help)
33
- COMPREPLY=( $(compgen -W "${commands}" ${current}) );;
34
- * )
35
- COMPREPLY=( $(compgen -f ${current}) );;
36
- esac
37
- }
38
- complete -F _#{COMMAND_NAME} #{COMMAND_NAME}
39
- EOS
40
-
41
- file = "#{ENV['HOME']}/.#{COMMAND_NAME}.d/completion.bash"
42
- FileUtils.mkdir_p(File.dirname(file))
43
- FileUtils.cp(file, "#{file}.#{Time.now.ymdhms}.bak") if File.file?(file)
44
- open(file, 'w').write(function)
45
-
46
- tilde_file = file.sub(/\A#{ENV['HOME']}/, '~')
47
- puts <<-EOS
48
- Please add following code to your ~/.bashrc if necessary.
49
-
50
- # enable seis_ruby completion.
51
- if [ -f #{tilde_file} ]; then
52
- . #{tilde_file}
53
- fi
54
- EOS
55
- end
56
- end
57
- end
58
- end
data/lib/seis_ruby/bin.rb DELETED
@@ -1,6 +0,0 @@
1
- module SeisRuby
2
- module Bin
3
- require 'ruby_patch'
4
- extend ::RubyPatch::AutoLoad
5
- end
6
- end
@@ -1,16 +0,0 @@
1
- module SeisRuby
2
- module Io
3
- module GcmtCatalog
4
- require 'mechanize'
5
-
6
- class CustomHtmlParser < ::Mechanize::Page
7
- require 'ruby_patch'
8
- extend ::RubyPatch::AutoLoad
9
-
10
- def initialize(uri = nil, response = nil, body = nil, code = nil, mech = nil)
11
- super(uri, response, body.gsub(/<=/, '&lt;='), code, mech)
12
- end
13
- end
14
- end
15
- end
16
- end
@@ -1,50 +0,0 @@
1
- module SeisRuby
2
- module Io
3
- module GcmtCatalog
4
- require 'rainbow'
5
- require 'mechanize'
6
- require 'ruby_patch'
7
- extend ::RubyPatch::AutoLoad
8
-
9
- module_function
10
-
11
- # @param [String] url URL of a first page of Global CMT Catalog search result.
12
- # @return [Array<Hash>] {::SeisRuby::Data::Cmtsolution#parse}
13
- def scrape(url)
14
- agent = Mechanize.new{|a|
15
- a.pluggable_parser.html = ::SeisRuby::Io::GcmtCatalog::CustomHtmlParser
16
- }
17
-
18
- result = {
19
- query: url,
20
- result: [],
21
- }
22
-
23
- while url
24
- agent.get(url)
25
- event_text_list = agent.page.search('pre')\
26
- .find{|e| e.text =~ /event name:/}\
27
- .text.split("\n\n")\
28
- .delete_if{|t| t.strip.empty?}
29
-
30
- begin
31
- event_list = ::SeisRuby::Data::Cmtsolution.parse(event_text_list)
32
- rescue ::SeisRuby::Data::Cmtsolution::ParseError => e
33
- $stderr.puts e.class.to_s.color(:red)
34
- $stderr.puts e.message
35
- ensure
36
- result[:result].concat event_list
37
- end
38
-
39
- url = nil
40
- if next_link = agent.page.links\
41
- .find{|e| e.text == 'More solutions'}
42
- url = next_link.uri
43
- end
44
- end
45
-
46
- result
47
- end
48
- end
49
- end
50
- end
data/lib/seis_ruby/io.rb DELETED
@@ -1,6 +0,0 @@
1
- module SeisRuby
2
- module Io
3
- require 'ruby_patch'
4
- extend ::RubyPatch::AutoLoad
5
- end
6
- end
data/rakefile DELETED
@@ -1,8 +0,0 @@
1
- require 'rspec/core/rake_task'
2
-
3
- task default: :spec
4
-
5
- desc "Run specs"
6
- RSpec::Core::RakeTask.new(:spec){|s|
7
- s.rspec_opts = '-c'
8
- }
@@ -1,83 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ::SeisRuby::Data::Cmtsolution do
4
- before :each do
5
- @valid_data = <<-EOS
6
- 1980 12 7 17 37 9.70 36.0300 1.2300 10.0 0.0 0.0
7
- event name: 120780A
8
- time shift: 1.7000
9
- half duration: 2.0000
10
- latitude: 36.0200
11
- longitude: 0.9400
12
- depth: 25.8000
13
- Mrr: 1.747000e+24
14
- Mtt: -2.197000e+24
15
- Mpp: 4.500000e+23
16
- Mrt: 7.430000e+23
17
- Mrp: 1.376000e+24
18
- Mtp: -1.491000e+24
19
- EOS
20
-
21
- @parsed_valid_data = {
22
- hypocenter: {
23
- data_source: '',
24
- year: 1980,
25
- month: 12,
26
- day: 7,
27
- hour: 17,
28
- minute: 37,
29
- second: 9.70,
30
- latitude: 36.03,
31
- longitude: 1.23,
32
- depth: 10.0,
33
- mb: 0.0,
34
- ms: 0.0,
35
- region_name: ''
36
- },
37
- event_name: '120780A',
38
- centroid: {
39
- time_shift: 1.7,
40
- half_duration: 2.0,
41
- latitude: 36.02,
42
- longitude: 0.94,
43
- depth: 25.8,
44
- mrr: 1.747e+24,
45
- mtt: -2.197e+24,
46
- mpp: 4.5e+23,
47
- mrt: 7.43e+23,
48
- mrp: 1.376e+24,
49
- mtp: -1.491e+24,
50
- },
51
- }
52
-
53
- @wrong_data = <<-EOS
54
- 1980 12 7 17 37 9.70 36.0300 1.2300 10.0 0.0
55
- event name: 120780A
56
- time shift: 1.7000
57
- half duration: 2.0000
58
- latitude: 36.0200
59
- longitude: 0.9400
60
- depth: 25.8000
61
- Mrr: 1.747000e+24
62
- Mtt: -2.197000e+24
63
- Mpp: 4.500000e+23
64
- Mrt: 7.430000e+23
65
- Mrp: 1.376000e+24
66
- Mtp: -1.491000e+24
67
- EOS
68
- end
69
-
70
- describe '.parse' do
71
- context 'normal case' do
72
- it do
73
- ::SeisRuby::Data::Cmtsolution.parse(@valid_data, @valid_data, [@valid_data, @valid_data]).should == [@parsed_valid_data, @parsed_valid_data, @parsed_valid_data, @parsed_valid_data]
74
- end
75
- end
76
-
77
- context 'wrong case' do
78
- it do
79
- lambda{::SeisRuby::Data::Cmtsolution.parse([@valid_data, @wrong_data])}.should raise_error(::SeisRuby::Data::Cmtsolution::ParseError)
80
- end
81
- end
82
- end
83
- end
@@ -1,19 +0,0 @@
1
- require 'yaml'
2
- require 'ruby_patch'
3
- require 'spec_helper'
4
-
5
- describe ::SeisRuby::Io::GcmtCatalog do
6
- describe '.scrape' do
7
- context 'normal case' do
8
- it do
9
- ::SeisRuby::Io::GcmtCatalog.scrape('http://www.globalcmt.org/cgi-bin/globalcmt-cgi-bin/CMT4/form?itype=ymd&yr=1976&mo=1&day=1&oyr=1976&omo=1&oday=1&jyr=1976&jday=1&ojyr=1&ojday=1&otype=nd&nday=400&lmw=0&umw=10&lms=0&ums=10&lmb=0&umb=10&llat=-90&ulat=90&llon=-180&ulon=180&lhd=0&uhd=1000&lts=-9999&uts=9999&lpe1=0&upe1=90&lpe2=0&upe2=90&list=4').should == YAML.load_file(File.join(__DIR__, 'scrape.yaml'))
10
- end
11
-
12
- context 'wrong case' do
13
- it do
14
- lambda{::SeisRuby::Io::GcmtCatalog.scrape('http://www.globalcmt.org/cgi-bin/globalcmt-cgi-bin/CMT4/form?itype=ymd&yr=1976&mo=1&day=1&oyr=1976&omo=1&oday=1&jyr=1976&jday=1&ojyr=1&ojday=1&otype=nd&nday=400&lmw=0&umw=10&lms=0&ums=10&lmb=0&umb=10&llat=-90&ulat=90&llon=-180&ulon=180&lhd=0&uhd=1000&lts=-9999&uts=9999&lpe1=0&upe1=90&lpe2=0&upe2=90&list=3')}.should raise_error
15
- end
16
- end
17
- end
18
- end
19
- end