puertos 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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +14 -0
- data/Guardfile +77 -0
- data/LICENSE.txt +22 -0
- data/README.md +38 -0
- data/Rakefile +9 -0
- data/lib/parser.rb +18 -0
- data/lib/puertos/version.rb +3 -0
- data/lib/puertos.rb +8 -0
- data/lib/row_parser.rb +53 -0
- data/lib/swell_data.rb +11 -0
- data/lib/wind_data.rb +9 -0
- data/puertos.gemspec +24 -0
- data/spec/puertos_spec.rb +21 -0
- data/spec/spec_helper.rb +4 -0
- metadata +103 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 7b966b0e6c7533b0658dffb9bf1fbc55225131c0
|
|
4
|
+
data.tar.gz: 1452503be21e7662b8481f553539b093f045f638
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 482508b2961db645d5f4c79a2ac3ef8ab2c4c907278521672d6bb2d5ee3dd999e7782145a7feeec4707d7461948c13bed0ff5822579101e111ca70602c17b4e0
|
|
7
|
+
data.tar.gz: 67ae52cb1a8c87ecbf74f4c3ab110985a2c6f7596e41bb6bbb8b26bf0ad968767113eb367fe1473a6fab2cec03528db9dda099b526f1d4c5b5c70593e24474b5
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# A sample Guardfile
|
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
|
3
|
+
|
|
4
|
+
## Uncomment and set this to only include directories you want to watch
|
|
5
|
+
# directories %w(app lib config test spec features)
|
|
6
|
+
|
|
7
|
+
## Uncomment to clear the screen before every task
|
|
8
|
+
# clearing :on
|
|
9
|
+
|
|
10
|
+
## Guard internally checks for changes in the Guardfile and exits.
|
|
11
|
+
## If you want Guard to automatically start up again, run guard in a
|
|
12
|
+
## shell loop, e.g.:
|
|
13
|
+
##
|
|
14
|
+
## $ while bundle exec guard; do echo "Restarting Guard..."; done
|
|
15
|
+
##
|
|
16
|
+
## Note: if you are using the `directories` clause above and you are not
|
|
17
|
+
## watching the project directory ('.'), then you will want to move
|
|
18
|
+
## the Guardfile to a watched dir and symlink it back, e.g.
|
|
19
|
+
#
|
|
20
|
+
# $ mkdir config
|
|
21
|
+
# $ mv Guardfile config/
|
|
22
|
+
# $ ln -s config/Guardfile .
|
|
23
|
+
#
|
|
24
|
+
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
|
|
25
|
+
|
|
26
|
+
# Note: The cmd option is now required due to the increasing number of ways
|
|
27
|
+
# rspec may be run, below are examples of the most common uses.
|
|
28
|
+
# * bundler: 'bundle exec rspec'
|
|
29
|
+
# * bundler binstubs: 'bin/rspec'
|
|
30
|
+
# * spring: 'bin/rspec' (This will use spring if running and you have
|
|
31
|
+
# installed the spring binstubs per the docs)
|
|
32
|
+
# * zeus: 'zeus rspec' (requires the server to be started separately)
|
|
33
|
+
# * 'just' rspec: 'rspec'
|
|
34
|
+
|
|
35
|
+
guard :rspec, cmd: "bundle exec rspec" do
|
|
36
|
+
require "guard/rspec/dsl"
|
|
37
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
|
38
|
+
|
|
39
|
+
# Feel free to open issues for suggestions and improvements
|
|
40
|
+
|
|
41
|
+
# RSpec files
|
|
42
|
+
rspec = dsl.rspec
|
|
43
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
|
44
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
|
45
|
+
watch(rspec.spec_files)
|
|
46
|
+
|
|
47
|
+
# Ruby files
|
|
48
|
+
ruby = dsl.ruby
|
|
49
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
|
50
|
+
|
|
51
|
+
# Rails files
|
|
52
|
+
rails = dsl.rails(view_extensions: %w(erb haml slim))
|
|
53
|
+
dsl.watch_spec_files_for(rails.app_files)
|
|
54
|
+
dsl.watch_spec_files_for(rails.views)
|
|
55
|
+
|
|
56
|
+
watch(rails.controllers) do |m|
|
|
57
|
+
[
|
|
58
|
+
rspec.spec.("routing/#{m[1]}_routing"),
|
|
59
|
+
rspec.spec.("controllers/#{m[1]}_controller"),
|
|
60
|
+
rspec.spec.("acceptance/#{m[1]}")
|
|
61
|
+
]
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Rails config changes
|
|
65
|
+
watch(rails.spec_helper) { rspec.spec_dir }
|
|
66
|
+
watch(rails.routes) { "#{rspec.spec_dir}/routing" }
|
|
67
|
+
watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
|
|
68
|
+
|
|
69
|
+
# Capybara features specs
|
|
70
|
+
watch(rails.view_dirs) { |m| rspec.spec.("features/#{m[1]}") }
|
|
71
|
+
|
|
72
|
+
# Turnip features and steps
|
|
73
|
+
watch(%r{^spec/acceptance/(.+)\.feature$})
|
|
74
|
+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
|
|
75
|
+
Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
|
|
76
|
+
end
|
|
77
|
+
end
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2015 Raul Galindo rgalindo33@gmail.com
|
|
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,38 @@
|
|
|
1
|
+
# Puertos
|
|
2
|
+
|
|
3
|
+
simple ruby gem that fetches the forecast swell data for Barcelona from Puertos del Estado
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
gem 'puertos'
|
|
10
|
+
|
|
11
|
+
And then execute:
|
|
12
|
+
|
|
13
|
+
$ bundle
|
|
14
|
+
|
|
15
|
+
Or install it yourself as:
|
|
16
|
+
|
|
17
|
+
$ gem install puertos
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
Make sure you require the gem before:
|
|
22
|
+
|
|
23
|
+
require 'puertos'
|
|
24
|
+
|
|
25
|
+
and then there is the one and only command available
|
|
26
|
+
|
|
27
|
+
Puertos.fetch
|
|
28
|
+
|
|
29
|
+
returns the swell and wind data for the next 72 hours
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
## Contributing
|
|
33
|
+
|
|
34
|
+
1. Fork it ( https://github.com/[my-github-username]/pont_del_petroli/fork )
|
|
35
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
36
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
37
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
38
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/parser.rb
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require 'row_parser'
|
|
2
|
+
require 'open-uri'
|
|
3
|
+
require 'nokogiri'
|
|
4
|
+
|
|
5
|
+
module Puertos
|
|
6
|
+
class Parser
|
|
7
|
+
DATA_URL = 'http://static.puertos.es/pred_simplificada/Predolas/Tablas/Med/BAR.html'
|
|
8
|
+
CSS_ROWS_SELECTOR = 'center center table tr'
|
|
9
|
+
|
|
10
|
+
def run
|
|
11
|
+
rows = Nokogiri::HTML(open(DATA_URL)).css CSS_ROWS_SELECTOR
|
|
12
|
+
|
|
13
|
+
rows.drop(2).map do |row|
|
|
14
|
+
Puertos::RowParser.new(row).run
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
data/lib/puertos.rb
ADDED
data/lib/row_parser.rb
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
require "wind_data"
|
|
2
|
+
require "swell_data"
|
|
3
|
+
|
|
4
|
+
module Puertos
|
|
5
|
+
class RowParser
|
|
6
|
+
|
|
7
|
+
attr_reader :row
|
|
8
|
+
|
|
9
|
+
def initialize row
|
|
10
|
+
@row = row
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def run
|
|
14
|
+
timestamp = read_column(1)
|
|
15
|
+
wind = create_wind_data
|
|
16
|
+
total_swell = create_total_swell_data
|
|
17
|
+
wind_swell = create_wind_swell_data
|
|
18
|
+
ground_swell_1 = create_ground_swell_data_1
|
|
19
|
+
ground_swell_2 = create_ground_swell_data_2
|
|
20
|
+
|
|
21
|
+
ForecastData.new wind, total_swell, wind_swell, ground_swell_1, ground_swell_2
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
def create_wind_data
|
|
27
|
+
Puertos::WindData.new speed: read_column(5), direction: read_column(6)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def create_total_swell_data
|
|
31
|
+
Puertos::SwellData.new height: read_column(7), direction: read_column(8), avg_period: read_column(10), peak_period: read_column(9)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def create_wind_swell_data
|
|
35
|
+
Puertos::SwellData.new height: read_column(11), direction: read_column(12)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def create_ground_swell_data_1
|
|
39
|
+
Puertos::SwellData.new height: read_column(13), direction: read_column(14), avg_period: read_column(15)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def create_ground_swell_data_2
|
|
43
|
+
Puertos::SwellData.new height: read_column(16), direction: read_column(17), avg_period: read_column(18)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def read_column number
|
|
47
|
+
row.css("td:nth-child(#{number})").text
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
class ForecastData < Struct.new :wind, :total_swell, :wind_swell, :ground_swell_1, :ground_swell_2
|
|
52
|
+
end
|
|
53
|
+
end
|
data/lib/swell_data.rb
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module Puertos
|
|
2
|
+
class SwellData
|
|
3
|
+
#remove after upgrading to ruby 2.1
|
|
4
|
+
def initialize(height: 1, direction: 'e', avg_period: nil, peak_period: nil)
|
|
5
|
+
@height = height
|
|
6
|
+
@direction = direction
|
|
7
|
+
@avg_period = avg_period
|
|
8
|
+
@peak_period = peak_period
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
data/lib/wind_data.rb
ADDED
data/puertos.gemspec
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'puertos/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "puertos"
|
|
8
|
+
spec.version = Puertos::VERSION
|
|
9
|
+
spec.authors = ["rgalindo33"]
|
|
10
|
+
spec.email = ["rgalindo33@hotmail.com"]
|
|
11
|
+
spec.summary = %q{Forecast swell information for Barcelona}
|
|
12
|
+
spec.description = %q{returns ruby objects with meaningfull swell data}
|
|
13
|
+
spec.homepage = "https://github.com/rgalindo33/puertos"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
+
spec.require_paths = ["lib"]
|
|
20
|
+
|
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
|
22
|
+
spec.add_development_dependency "rake"
|
|
23
|
+
spec.add_dependency "nokogiri"
|
|
24
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Puertos do
|
|
4
|
+
let(:subject) { Puertos }
|
|
5
|
+
|
|
6
|
+
describe '#run' do
|
|
7
|
+
let(:forecast) { subject.fetch }
|
|
8
|
+
|
|
9
|
+
it 'returns an array' do
|
|
10
|
+
expect(forecast).to be_an Array
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it 'objects of the array are forecast data' do
|
|
14
|
+
expect(forecast.first).to be_a Puertos::ForecastData
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it 'returns forecast data for the next 72 hours' do
|
|
18
|
+
expect(forecast.size).to eq 73
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: puertos
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- rgalindo33
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-04-11 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.5'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ~>
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.5'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - '>='
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - '>='
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: nokogiri
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - '>='
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - '>='
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
description: returns ruby objects with meaningfull swell data
|
|
56
|
+
email:
|
|
57
|
+
- rgalindo33@hotmail.com
|
|
58
|
+
executables: []
|
|
59
|
+
extensions: []
|
|
60
|
+
extra_rdoc_files: []
|
|
61
|
+
files:
|
|
62
|
+
- .gitignore
|
|
63
|
+
- Gemfile
|
|
64
|
+
- Guardfile
|
|
65
|
+
- LICENSE.txt
|
|
66
|
+
- README.md
|
|
67
|
+
- Rakefile
|
|
68
|
+
- lib/parser.rb
|
|
69
|
+
- lib/puertos.rb
|
|
70
|
+
- lib/puertos/version.rb
|
|
71
|
+
- lib/row_parser.rb
|
|
72
|
+
- lib/swell_data.rb
|
|
73
|
+
- lib/wind_data.rb
|
|
74
|
+
- puertos.gemspec
|
|
75
|
+
- spec/puertos_spec.rb
|
|
76
|
+
- spec/spec_helper.rb
|
|
77
|
+
homepage: https://github.com/rgalindo33/puertos
|
|
78
|
+
licenses:
|
|
79
|
+
- MIT
|
|
80
|
+
metadata: {}
|
|
81
|
+
post_install_message:
|
|
82
|
+
rdoc_options: []
|
|
83
|
+
require_paths:
|
|
84
|
+
- lib
|
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - '>='
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0'
|
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
|
+
requirements:
|
|
92
|
+
- - '>='
|
|
93
|
+
- !ruby/object:Gem::Version
|
|
94
|
+
version: '0'
|
|
95
|
+
requirements: []
|
|
96
|
+
rubyforge_project:
|
|
97
|
+
rubygems_version: 2.2.2
|
|
98
|
+
signing_key:
|
|
99
|
+
specification_version: 4
|
|
100
|
+
summary: Forecast swell information for Barcelona
|
|
101
|
+
test_files:
|
|
102
|
+
- spec/puertos_spec.rb
|
|
103
|
+
- spec/spec_helper.rb
|