buoy_data 0.1.0
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.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.markdown +32 -0
- data/Rakefile +55 -0
- data/VERSION +1 -0
- data/buoy_data.gemspec +59 -0
- data/lib/buoy_data/buoy.rb +7 -0
- data/lib/buoy_data/noaa_buoy.rb +70 -0
- data/lib/buoy_data.rb +3 -0
- data/spec/noaa_buoy_spec.rb +20 -0
- data/spec/spec_helper.rb +15 -0
- metadata +102 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Adam Weller
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# buoy_data
|
2
|
+
|
3
|
+
The goal of this gem is to provide marine buoy data from a variety of sources.
|
4
|
+
|
5
|
+
## Install
|
6
|
+
|
7
|
+
<pre>
|
8
|
+
gem install buoy_data
|
9
|
+
</pre>
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
<pre>
|
14
|
+
require 'buoy_data'
|
15
|
+
noaa_buoy = BuoyData::NoaaBuoy.new(41114)
|
16
|
+
noaa_buoy.get
|
17
|
+
noaa_buoy.WVHT
|
18
|
+
</pre>
|
19
|
+
|
20
|
+
## Note on Patches/Pull Requests
|
21
|
+
|
22
|
+
* Fork the project.
|
23
|
+
* Make your feature addition or bug fix.
|
24
|
+
* Add tests for it. This is important so I don't break it in a
|
25
|
+
future version unintentionally.
|
26
|
+
* Commit, do not mess with rakefile, version, or history.
|
27
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
28
|
+
* Send me a pull request. Bonus points for topic branches.
|
29
|
+
|
30
|
+
## Copyright
|
31
|
+
|
32
|
+
Copyright (c) 2010 Adam Weller. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "buoy_data"
|
8
|
+
gem.summary = %Q{Fetch marine buoy data from various sources}
|
9
|
+
gem.description = %Q{The goal of this gem is to provide marine buoy data from a variety of sources}
|
10
|
+
gem.email = "minch@trazzler.com"
|
11
|
+
gem.homepage = "http://github.com/minch/buoy_data"
|
12
|
+
gem.authors = ["Adam Weller"]
|
13
|
+
gem.add_development_dependency 'rspec'
|
14
|
+
gem.add_dependency 'httparty'
|
15
|
+
gem.files.include 'lib/buoy_data/*.rb'
|
16
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
|
+
end
|
18
|
+
Jeweler::GemcutterTasks.new
|
19
|
+
rescue LoadError
|
20
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'rake/testtask'
|
24
|
+
Rake::TestTask.new(:test) do |test|
|
25
|
+
test.libs << 'lib' << 'test'
|
26
|
+
test.pattern = 'test/**/test_*.rb'
|
27
|
+
test.verbose = true
|
28
|
+
end
|
29
|
+
|
30
|
+
begin
|
31
|
+
require 'rcov/rcovtask'
|
32
|
+
Rcov::RcovTask.new do |test|
|
33
|
+
test.libs << 'test'
|
34
|
+
test.pattern = 'test/**/test_*.rb'
|
35
|
+
test.verbose = true
|
36
|
+
end
|
37
|
+
rescue LoadError
|
38
|
+
task :rcov do
|
39
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
task :test => :check_dependencies
|
44
|
+
|
45
|
+
task :default => :test
|
46
|
+
|
47
|
+
require 'rake/rdoctask'
|
48
|
+
Rake::RDocTask.new do |rdoc|
|
49
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
50
|
+
|
51
|
+
rdoc.rdoc_dir = 'rdoc'
|
52
|
+
rdoc.title = "buoy_data #{version}"
|
53
|
+
rdoc.rdoc_files.include('README*')
|
54
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
55
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/buoy_data.gemspec
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{buoy_data}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Adam Weller"]
|
12
|
+
s.date = %q{2010-10-26}
|
13
|
+
s.description = %q{The goal of this gem is to provide marine buoy data from a variety of sources}
|
14
|
+
s.email = %q{minch@trazzler.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.markdown"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.markdown",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"buoy_data.gemspec",
|
27
|
+
"lib/buoy_data.rb",
|
28
|
+
"lib/buoy_data/buoy.rb",
|
29
|
+
"lib/buoy_data/noaa_buoy.rb",
|
30
|
+
"spec/noaa_buoy_spec.rb",
|
31
|
+
"spec/spec_helper.rb"
|
32
|
+
]
|
33
|
+
s.homepage = %q{http://github.com/minch/buoy_data}
|
34
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
35
|
+
s.require_paths = ["lib"]
|
36
|
+
s.rubygems_version = %q{1.3.7}
|
37
|
+
s.summary = %q{Fetch marine buoy data from various sources}
|
38
|
+
s.test_files = [
|
39
|
+
"spec/noaa_buoy_spec.rb",
|
40
|
+
"spec/spec_helper.rb"
|
41
|
+
]
|
42
|
+
|
43
|
+
if s.respond_to? :specification_version then
|
44
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
45
|
+
s.specification_version = 3
|
46
|
+
|
47
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
48
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
49
|
+
s.add_runtime_dependency(%q<httparty>, [">= 0"])
|
50
|
+
else
|
51
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
52
|
+
s.add_dependency(%q<httparty>, [">= 0"])
|
53
|
+
end
|
54
|
+
else
|
55
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
56
|
+
s.add_dependency(%q<httparty>, [">= 0"])
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module BuoyData
|
2
|
+
class NoaaBuoy < Buoy
|
3
|
+
format :plain
|
4
|
+
|
5
|
+
attr_accessor :buoy_id, :url, :response
|
6
|
+
|
7
|
+
def initialize(buoy_id)
|
8
|
+
@url = base_url(buoy_id)
|
9
|
+
end
|
10
|
+
|
11
|
+
def metaclass
|
12
|
+
class << self
|
13
|
+
self
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def get(raw = false)
|
18
|
+
response = self.class.get(@url)
|
19
|
+
return unless response and response.code == GET_SUCCESS
|
20
|
+
return response if raw
|
21
|
+
|
22
|
+
@response = response
|
23
|
+
parse_response
|
24
|
+
end
|
25
|
+
|
26
|
+
def base_url(buoy_id = @buoy_id)
|
27
|
+
@buoy_id ||= buoy_id
|
28
|
+
|
29
|
+
# The following didn't work as the :description field contains markup we'd have
|
30
|
+
# to parse
|
31
|
+
#"http://www.ndbc.noaa.gov/data/latest_obs/#{id}.rss"
|
32
|
+
|
33
|
+
# TODO: get historical data from:
|
34
|
+
"http://www.ndbc.noaa.gov/data/realtime2/#{buoy_id}.spec"
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.source
|
38
|
+
:noaa
|
39
|
+
end
|
40
|
+
|
41
|
+
def parse_response
|
42
|
+
# Get all readings
|
43
|
+
response = @response.parsed_response.split(/\n/)
|
44
|
+
|
45
|
+
# The first line are the fields
|
46
|
+
fields = response.first.sub(/^#/, '').split
|
47
|
+
|
48
|
+
# The second line are different names of the fields
|
49
|
+
|
50
|
+
# The third line is the most recent reading
|
51
|
+
response = response[2].split rescue nil
|
52
|
+
return unless response
|
53
|
+
|
54
|
+
# Set instance vars per field so we can use dot notation to reference each
|
55
|
+
hash = {}
|
56
|
+
fields.each_with_index do |field, index|
|
57
|
+
hash.store(field, response[index])
|
58
|
+
end
|
59
|
+
|
60
|
+
define_attributes(hash)
|
61
|
+
end
|
62
|
+
|
63
|
+
def define_attributes(hash)
|
64
|
+
hash.each_pair { |key, value|
|
65
|
+
metaclass.send :attr_accessor, key
|
66
|
+
send "#{key}=".to_sym, value
|
67
|
+
}
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/lib/buoy_data.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
describe BuoyData::NoaaBuoy do
|
4
|
+
before(:each) do
|
5
|
+
#WebMock.allow_net_connect! # TODO
|
6
|
+
@noaa_buoy = BuoyData::NoaaBuoy.new(41114)
|
7
|
+
end
|
8
|
+
|
9
|
+
context 'get' do
|
10
|
+
it 'should get buoy data' do
|
11
|
+
@noaa_buoy.get
|
12
|
+
@noaa_buoy.response.code.should == BuoyData::NoaaBuoy::GET_SUCCESS
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should respond to noaa fields' do
|
16
|
+
@noaa_buoy.get
|
17
|
+
@noaa_buoy.should respond_to :WVHT
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: buoy_data
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Adam Weller
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-10-26 00:00:00 -04:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rspec
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
type: :development
|
32
|
+
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: httparty
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
version: "0"
|
44
|
+
type: :runtime
|
45
|
+
version_requirements: *id002
|
46
|
+
description: The goal of this gem is to provide marine buoy data from a variety of sources
|
47
|
+
email: minch@trazzler.com
|
48
|
+
executables: []
|
49
|
+
|
50
|
+
extensions: []
|
51
|
+
|
52
|
+
extra_rdoc_files:
|
53
|
+
- LICENSE
|
54
|
+
- README.markdown
|
55
|
+
files:
|
56
|
+
- .document
|
57
|
+
- .gitignore
|
58
|
+
- LICENSE
|
59
|
+
- README.markdown
|
60
|
+
- Rakefile
|
61
|
+
- VERSION
|
62
|
+
- buoy_data.gemspec
|
63
|
+
- lib/buoy_data.rb
|
64
|
+
- lib/buoy_data/buoy.rb
|
65
|
+
- lib/buoy_data/noaa_buoy.rb
|
66
|
+
- spec/noaa_buoy_spec.rb
|
67
|
+
- spec/spec_helper.rb
|
68
|
+
has_rdoc: true
|
69
|
+
homepage: http://github.com/minch/buoy_data
|
70
|
+
licenses: []
|
71
|
+
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options:
|
74
|
+
- --charset=UTF-8
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
segments:
|
83
|
+
- 0
|
84
|
+
version: "0"
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
segments:
|
91
|
+
- 0
|
92
|
+
version: "0"
|
93
|
+
requirements: []
|
94
|
+
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 1.3.7
|
97
|
+
signing_key:
|
98
|
+
specification_version: 3
|
99
|
+
summary: Fetch marine buoy data from various sources
|
100
|
+
test_files:
|
101
|
+
- spec/noaa_buoy_spec.rb
|
102
|
+
- spec/spec_helper.rb
|