ndbc 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,45 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://www.ndbc.noaa.gov/data/realtime2/0.txt
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.1
12
+ Accept-Encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ Accept:
15
+ - "*/*"
16
+ response:
17
+ status:
18
+ code: 404
19
+ message: Not Found
20
+ headers:
21
+ Date:
22
+ - Sun, 13 Dec 2015 15:50:09 GMT
23
+ Server:
24
+ - Apache
25
+ Vary:
26
+ - Accept-Encoding
27
+ Content-Length:
28
+ - '188'
29
+ Connection:
30
+ - close
31
+ Content-Type:
32
+ - text/html; charset=iso-8859-1
33
+ body:
34
+ encoding: UTF-8
35
+ string: |
36
+ <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
37
+ <html><head>
38
+ <title>404 Not Found</title>
39
+ </head><body>
40
+ <h1>Not Found</h1>
41
+ <p>The requested URL /data/realtime2/0.txt was not found on this server.</p>
42
+ </body></html>
43
+ http_version:
44
+ recorded_at: Sun, 13 Dec 2015 15:50:10 GMT
45
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,45 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://www.ndbc.noaa.gov/data/realtime2/0.txt
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.0
12
+ Accept-Encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ Accept:
15
+ - "*/*"
16
+ response:
17
+ status:
18
+ code: 404
19
+ message: Not Found
20
+ headers:
21
+ Date:
22
+ - Sun, 16 Aug 2015 22:38:44 GMT
23
+ Server:
24
+ - Apache
25
+ Vary:
26
+ - Accept-Encoding
27
+ Content-Length:
28
+ - '188'
29
+ Connection:
30
+ - close
31
+ Content-Type:
32
+ - text/html; charset=iso-8859-1
33
+ body:
34
+ encoding: UTF-8
35
+ string: |
36
+ <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
37
+ <html><head>
38
+ <title>404 Not Found</title>
39
+ </head><body>
40
+ <h1>Not Found</h1>
41
+ <p>The requested URL /data/realtime2/0.txt was not found on this server.</p>
42
+ </body></html>
43
+ http_version:
44
+ recorded_at: Sun, 16 Aug 2015 22:38:44 GMT
45
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe NDBC::Connection do
4
+
5
+ describe "initialization" do
6
+ it "creates a Faraday connection" do
7
+ expect(Faraday).to receive(:new)
8
+ NDBC::Connection.new
9
+ end
10
+ end
11
+
12
+ describe "get" do
13
+ let(:connection) { NDBC::Connection.new }
14
+
15
+ it "gets" do
16
+ expect(connection).to respond_to(:get)
17
+ end
18
+
19
+ it "handles 404's" do
20
+ VCR.use_cassette("not_found") do
21
+ expect{ connection.get("http://www.ndbc.noaa.gov/not_found") }.to raise_error(NDBC::NotFound)
22
+ end
23
+ end
24
+
25
+ end
26
+
27
+ end
@@ -0,0 +1,165 @@
1
+ require 'spec_helper'
2
+
3
+ describe NDBC::Station do
4
+
5
+ let(:station) { NDBC::Station.new(41009) }
6
+
7
+ describe "initialization" do
8
+
9
+ it "assigns the id" do
10
+ expect(station.id).to eq("41009")
11
+ end
12
+
13
+ it "has a connection" do
14
+ expect(station).to respond_to(:connection)
15
+ end
16
+
17
+ end
18
+
19
+ shared_examples_for "station" do
20
+
21
+ it "returns a hash with units and values" do
22
+ expect(result[:units]).to be_a(Hash)
23
+ expect(result[:values]).to be_a(Array)
24
+ end
25
+
26
+ it "returns and array of values that are hashes" do
27
+ expect(result[:values].first).to be_a(Hash)
28
+ end
29
+
30
+ describe "units" do
31
+ it "removes the # from the first two lines of raw text" do
32
+ expect(result[:units]["YY"]).to eq("yr")
33
+ end
34
+ end
35
+
36
+ describe "values" do
37
+ it "replaces 'MM' with nil" do
38
+ mm_found = false
39
+ result[:values].each do |row|
40
+ if row.values.include?("MM")
41
+ mm_found = true
42
+ break
43
+ end
44
+ end
45
+ expect(mm_found).to be false
46
+ end
47
+
48
+ it "skips the first two rows of raw data" do
49
+ expect(result[:values].first["YY"]).to eq("2015")
50
+ end
51
+ end
52
+
53
+ end
54
+
55
+ describe "standard_meteorological_data" do
56
+
57
+ let(:result) do
58
+ VCR.use_cassette("standard_meteorological_data") do
59
+ station.standard_meteorological_data
60
+ end
61
+ end
62
+
63
+ it_behaves_like "station"
64
+
65
+ context 'when the station is not found' do
66
+
67
+ let(:not_found_station) { NDBC::Station.new(00000) }
68
+
69
+ let(:not_found_result) do
70
+ VCR.use_cassette("standard_meteorological_data_not_found") do
71
+ not_found_station.standard_meteorological_data
72
+ end
73
+ end
74
+
75
+ it "returns a hash with units and values" do
76
+ expect(not_found_result[:units]).to be_a(Hash)
77
+ expect(not_found_result[:values]).to be_a(Array)
78
+ end
79
+
80
+ end
81
+
82
+ end
83
+
84
+ describe "meteorological data from drifting buoys" do
85
+ end
86
+
87
+ describe "continuous winds data" do
88
+ let(:result) do
89
+ VCR.use_cassette("continuous_winds_data") do
90
+ station.continuous_winds_data
91
+ end
92
+ end
93
+
94
+ it_behaves_like "station"
95
+ end
96
+
97
+ describe "spectral wave summaries" do
98
+ let(:result) do
99
+ VCR.use_cassette("spectral_wave_summaries") do
100
+ station.spectral_wave_summaries
101
+ end
102
+ end
103
+
104
+ it_behaves_like "station"
105
+ end
106
+
107
+ describe "error handling" do
108
+
109
+ let(:not_found) do
110
+ NDBC::Station.new(00000)
111
+ end
112
+
113
+ it "catches 404's" do
114
+ VCR.use_cassette("station_not_found") do
115
+ expect{not_found.standard_meteorological_data}.not_to raise_error
116
+ end
117
+
118
+ end
119
+ end
120
+
121
+ describe "spectral wave forecasts" do
122
+
123
+ let(:buoy) { NDBC::Station.new(41009) }
124
+
125
+ let(:response) do
126
+ VCR.use_cassette("spectral_wave_forecasts") do
127
+ buoy.spectral_wave_forecasts
128
+ end
129
+ end
130
+
131
+ it "makes a request" do
132
+ expect(buoy.connection).to receive(:get).with("http://polar.ncep.noaa.gov/waves/WEB/multi_1.latest_run/plots/multi_1.41009.bull")
133
+ buoy.spectral_wave_forecasts
134
+ end
135
+
136
+ it "parses the cycle line and uses it to set up the first date" do
137
+ expect(response.first[:time]).to eq( DateTime.new(2015, 9, 7, 3) )
138
+ end
139
+
140
+ it "returns an array of hashes with a height key" do
141
+ expect(response.first[:hst]).to be_a Float
142
+ end
143
+
144
+ it "returns an array of hashes with a swells array" do
145
+ expect(response.first[:swells]).to be_a Array
146
+ end
147
+
148
+ it "returns an array of hashes with a swells array, that contains hashes with hs, tp, and dir" do
149
+ swell = response.first[:swells].first
150
+ expect(swell[:hs]).to be_a Float
151
+ expect(swell[:tp]).to be_a Float
152
+ expect(swell[:dir]).to be_a Fixnum
153
+ end
154
+
155
+ describe "times" do
156
+
157
+ it "calculates the right time" do
158
+ expect(response[1][:time]).to eq( response.first[:time] + 1.hour )
159
+ end
160
+
161
+ end
162
+
163
+ end
164
+
165
+ end
data/spec/ndbc_spec.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe NDBC do
4
+
5
+ end
@@ -0,0 +1,105 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+
20
+ require 'ndbc'
21
+ require 'vcr'
22
+
23
+ RSpec.configure do |config|
24
+ # rspec-expectations config goes here. You can use an alternate
25
+ # assertion/expectation library such as wrong or the stdlib/minitest
26
+ # assertions if you prefer.
27
+ config.expect_with :rspec do |expectations|
28
+ # This option will default to `true` in RSpec 4. It makes the `description`
29
+ # and `failure_message` of custom matchers include text for helper methods
30
+ # defined using `chain`, e.g.:
31
+ # be_bigger_than(2).and_smaller_than(4).description
32
+ # # => "be bigger than 2 and smaller than 4"
33
+ # ...rather than:
34
+ # # => "be bigger than 2"
35
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
36
+ end
37
+
38
+ # rspec-mocks config goes here. You can use an alternate test double
39
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
40
+ config.mock_with :rspec do |mocks|
41
+ # Prevents you from mocking or stubbing a method that does not exist on
42
+ # a real object. This is generally recommended, and will default to
43
+ # `true` in RSpec 4.
44
+ mocks.verify_partial_doubles = true
45
+ end
46
+
47
+ # The settings below are suggested to provide a good initial experience
48
+ # with RSpec, but feel free to customize to your heart's content.
49
+ =begin
50
+ # These two settings work together to allow you to limit a spec run
51
+ # to individual examples or groups you care about by tagging them with
52
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
53
+ # get run.
54
+ config.filter_run :focus
55
+ config.run_all_when_everything_filtered = true
56
+
57
+ # Allows RSpec to persist some state between runs in order to support
58
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
59
+ # you configure your source control system to ignore this file.
60
+ config.example_status_persistence_file_path = "spec/examples.txt"
61
+
62
+ # Limits the available syntax to the non-monkey patched syntax that is
63
+ # recommended. For more details, see:
64
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
65
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
66
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
67
+ config.disable_monkey_patching!
68
+
69
+ # This setting enables warnings. It's recommended, but in some cases may
70
+ # be too noisy due to issues in dependencies.
71
+ config.warnings = true
72
+
73
+ # Many RSpec users commonly either run the entire suite or an individual
74
+ # file, and it's useful to allow more verbose output when running an
75
+ # individual spec file.
76
+ if config.files_to_run.one?
77
+ # Use the documentation formatter for detailed output,
78
+ # unless a formatter has already been configured
79
+ # (e.g. via a command-line flag).
80
+ config.default_formatter = 'doc'
81
+ end
82
+
83
+ # Print the 10 slowest examples and example groups at the
84
+ # end of the spec run, to help surface which specs are running
85
+ # particularly slow.
86
+ config.profile_examples = 10
87
+
88
+ # Run specs in random order to surface order dependencies. If you find an
89
+ # order dependency and want to debug it, you can fix the order by providing
90
+ # the seed, which is printed after each run.
91
+ # --seed 1234
92
+ config.order = :random
93
+
94
+ # Seed global randomization in this process using the `--seed` CLI option.
95
+ # Setting this allows you to use `--seed` to deterministically reproduce
96
+ # test failures related to randomization by passing the same `--seed` value
97
+ # as the one that triggered the failure.
98
+ Kernel.srand config.seed
99
+ =end
100
+ end
101
+
102
+ VCR.configure do |config|
103
+ config.cassette_library_dir = "spec/fixtures/vcr_cassettes"
104
+ config.hook_into :webmock
105
+ end
metadata ADDED
@@ -0,0 +1,190 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ndbc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Hertz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard-rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: vcr
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: faraday
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: activesupport
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Get NDBC buoy data and possibly other stuff.
126
+ email:
127
+ - ''
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".rspec"
134
+ - Gemfile
135
+ - Guardfile
136
+ - LICENSE.txt
137
+ - README.md
138
+ - Rakefile
139
+ - lib/ndbc.rb
140
+ - lib/ndbc/connection.rb
141
+ - lib/ndbc/station.rb
142
+ - lib/ndbc/version.rb
143
+ - ndbc.gemspec
144
+ - spec/fixtures/vcr_cassettes/continuous_winds_data.yml
145
+ - spec/fixtures/vcr_cassettes/not_found.yml
146
+ - spec/fixtures/vcr_cassettes/spectral_wave_forecasts.yml
147
+ - spec/fixtures/vcr_cassettes/spectral_wave_summaries.yml
148
+ - spec/fixtures/vcr_cassettes/standard_meteorological_data.yml
149
+ - spec/fixtures/vcr_cassettes/standard_meteorological_data_not_found.yml
150
+ - spec/fixtures/vcr_cassettes/station_not_found.yml
151
+ - spec/ndbc/connection_spec.rb
152
+ - spec/ndbc/station_spec.rb
153
+ - spec/ndbc_spec.rb
154
+ - spec/spec_helper.rb
155
+ homepage: ''
156
+ licenses:
157
+ - MIT
158
+ metadata: {}
159
+ post_install_message:
160
+ rdoc_options: []
161
+ require_paths:
162
+ - lib
163
+ required_ruby_version: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ required_rubygems_version: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ requirements: []
174
+ rubyforge_project:
175
+ rubygems_version: 2.4.2
176
+ signing_key:
177
+ specification_version: 4
178
+ summary: Get NDBC buoy data.
179
+ test_files:
180
+ - spec/fixtures/vcr_cassettes/continuous_winds_data.yml
181
+ - spec/fixtures/vcr_cassettes/not_found.yml
182
+ - spec/fixtures/vcr_cassettes/spectral_wave_forecasts.yml
183
+ - spec/fixtures/vcr_cassettes/spectral_wave_summaries.yml
184
+ - spec/fixtures/vcr_cassettes/standard_meteorological_data.yml
185
+ - spec/fixtures/vcr_cassettes/standard_meteorological_data_not_found.yml
186
+ - spec/fixtures/vcr_cassettes/station_not_found.yml
187
+ - spec/ndbc/connection_spec.rb
188
+ - spec/ndbc/station_spec.rb
189
+ - spec/ndbc_spec.rb
190
+ - spec/spec_helper.rb