buoyancy 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +11 -0
- data/LICENSE.txt +22 -0
- data/README.md +41 -0
- data/Rakefile +8 -0
- data/buoyancy.gemspec +23 -0
- data/lib/buoyancy/connection.rb +13 -0
- data/lib/buoyancy/version.rb +3 -0
- data/lib/buoyancy.rb +50 -0
- data/test/buoyancy/connection_spec.rb +12 -0
- data/test/buoyancy_spec.rb +35 -0
- data/test/test_helper.rb +9 -0
- metadata +93 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Brandon Weiss
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Buoyancy
|
2
|
+
|
3
|
+
A Ruby gem for getting data from the NDBC (National Data Buoy Center). The data provided by these stations (buoys) is incredibly useful, but the data itself is inconsistent, poorly formatted, and somewhat difficult to figure out how to get. This gem is a wrapper that simplifies all of that.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem "buoyancy"
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install buoyancy
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
require "rubygems"
|
23
|
+
require "bundler"
|
24
|
+
Bundler.setup
|
25
|
+
|
26
|
+
require "buoyancy"
|
27
|
+
|
28
|
+
# Get a list of all the stations
|
29
|
+
Buoyancy.stations
|
30
|
+
|
31
|
+
# Meteorological data coming soon
|
32
|
+
# Buoyancy.station("0y2w3").meteorological
|
33
|
+
```
|
34
|
+
|
35
|
+
## Contributing
|
36
|
+
|
37
|
+
1. Fork it
|
38
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
39
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
40
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
41
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/buoyancy.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'buoyancy/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "buoyancy"
|
8
|
+
gem.version = Buoyancy::VERSION
|
9
|
+
gem.authors = ["Brandon Weiss"]
|
10
|
+
gem.email = ["brandon@anti-pattern.com"]
|
11
|
+
gem.description = %q{A Ruby gem for getting data from the NDBC (National Data Buoy Center)}
|
12
|
+
gem.summary = %q{A Ruby gem for getting data from the NDBC (National Data Buoy Center)}
|
13
|
+
gem.homepage = ""
|
14
|
+
gem.license = "MIT"
|
15
|
+
|
16
|
+
gem.files = `git ls-files`.split($/)
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
gem.require_paths = ["lib"]
|
20
|
+
|
21
|
+
gem.add_development_dependency "rake"
|
22
|
+
gem.add_dependency "faraday", "~> 0.8.4"
|
23
|
+
end
|
data/lib/buoyancy.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require "buoyancy/version"
|
2
|
+
require "buoyancy/connection"
|
3
|
+
|
4
|
+
module Buoyancy
|
5
|
+
|
6
|
+
def self.connection
|
7
|
+
@connection ||= Connection.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.stations
|
11
|
+
connection.get("stations/station_table.txt").body.split("\n").drop(2).each_with_object([]) do |station, array|
|
12
|
+
station_parts = station.split("|")
|
13
|
+
station_parts.map! { |part| part.strip unless part.nil? }
|
14
|
+
station_parts.map! { |part| (part == "" || part == "?") ? nil : part }
|
15
|
+
|
16
|
+
array << {
|
17
|
+
id: station_parts[0],
|
18
|
+
owner: station_parts[1],
|
19
|
+
type: station_parts[2],
|
20
|
+
hull: station_parts[3],
|
21
|
+
name: station_parts[4],
|
22
|
+
payload: station_parts[5],
|
23
|
+
location: extract_location(station_parts[6]),
|
24
|
+
time_zone: station_parts[7],
|
25
|
+
forecast: station_parts[8],
|
26
|
+
note: station_parts[9]
|
27
|
+
}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.extract_location(location)
|
32
|
+
return location unless location.match(/(\d+\.\d+\s(N|S|W|E)\s){2}\(.+\)$/)
|
33
|
+
|
34
|
+
location.gsub!(/\s{1}\(.+\)/, "")
|
35
|
+
parts = location.split(" ")
|
36
|
+
|
37
|
+
longitude_number = parts[0].to_f
|
38
|
+
latitude_number = parts[2].to_f
|
39
|
+
longitude_sign = parts[1]
|
40
|
+
latitude_sign = parts[3]
|
41
|
+
longitude = longitude_sign == "N" ? +longitude_number : -longitude_number
|
42
|
+
latitude = latitude_sign == "W" ? -latitude_number : +latitude_number
|
43
|
+
|
44
|
+
{
|
45
|
+
longitude: longitude,
|
46
|
+
latitude: latitude
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require File.expand_path("../../test_helper", __FILE__)
|
2
|
+
require "buoyancy/connection"
|
3
|
+
|
4
|
+
describe Buoyancy::Connection do
|
5
|
+
|
6
|
+
it "creates a Faraday connection" do
|
7
|
+
connection = stub
|
8
|
+
Faraday.expects(:new).with(url: "http://www.ndbc.noaa.gov/data").returns(connection)
|
9
|
+
Buoyancy::Connection.new.must_equal connection
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.expand_path("../test_helper", __FILE__)
|
2
|
+
require "buoyancy"
|
3
|
+
|
4
|
+
describe Buoyancy do
|
5
|
+
|
6
|
+
it "gets a list of stations" do
|
7
|
+
body = "#\n#\n0y2w3|CG|Weather Station|Adamantium|Some Island|A bomb|That way|?| ||"
|
8
|
+
response = mock { expects(:body).returns(body) }
|
9
|
+
connection = mock { expects(:get).with("stations/station_table.txt").returns(response) }
|
10
|
+
Buoyancy.expects(:connection).returns(connection)
|
11
|
+
Buoyancy.stations.must_equal [{
|
12
|
+
id: "0y2w3",
|
13
|
+
owner: "CG",
|
14
|
+
type: "Weather Station",
|
15
|
+
hull: "Adamantium",
|
16
|
+
name: "Some Island",
|
17
|
+
payload: "A bomb",
|
18
|
+
location: "That way",
|
19
|
+
time_zone: nil,
|
20
|
+
forecast: nil,
|
21
|
+
note: nil
|
22
|
+
}]
|
23
|
+
end
|
24
|
+
|
25
|
+
it "extracts a longitude and latitude from a location string with North and West coordinates" do
|
26
|
+
location = "44.794 N 87.313 W (44°47'40\" N 87°18'47\" W)"
|
27
|
+
Buoyancy.extract_location(location).must_equal({ longitude: 44.794, latitude: -87.313 })
|
28
|
+
end
|
29
|
+
|
30
|
+
it "extracts a longitude and latitude from a location string with South and East coordinates" do
|
31
|
+
location = "44.794 S 87.313 E (44°47'40\" N 87°18'47\" W)"
|
32
|
+
Buoyancy.extract_location(location).must_equal({ longitude: -44.794, latitude: 87.313 })
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: buoyancy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Brandon Weiss
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-23 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: faraday
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 0.8.4
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.8.4
|
46
|
+
description: A Ruby gem for getting data from the NDBC (National Data Buoy Center)
|
47
|
+
email:
|
48
|
+
- brandon@anti-pattern.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE.txt
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- buoyancy.gemspec
|
59
|
+
- lib/buoyancy.rb
|
60
|
+
- lib/buoyancy/connection.rb
|
61
|
+
- lib/buoyancy/version.rb
|
62
|
+
- test/buoyancy/connection_spec.rb
|
63
|
+
- test/buoyancy_spec.rb
|
64
|
+
- test/test_helper.rb
|
65
|
+
homepage: ''
|
66
|
+
licenses:
|
67
|
+
- MIT
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 1.8.23
|
87
|
+
signing_key:
|
88
|
+
specification_version: 3
|
89
|
+
summary: A Ruby gem for getting data from the NDBC (National Data Buoy Center)
|
90
|
+
test_files:
|
91
|
+
- test/buoyancy/connection_spec.rb
|
92
|
+
- test/buoyancy_spec.rb
|
93
|
+
- test/test_helper.rb
|