puertos 0.0.1 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7b966b0e6c7533b0658dffb9bf1fbc55225131c0
4
- data.tar.gz: 1452503be21e7662b8481f553539b093f045f638
3
+ metadata.gz: 2035415cbe891bce7c6d2302e7429df2d8c8466c
4
+ data.tar.gz: 7d6c4fc21a7f4009240e3ab8da62c166054f72b7
5
5
  SHA512:
6
- metadata.gz: 482508b2961db645d5f4c79a2ac3ef8ab2c4c907278521672d6bb2d5ee3dd999e7782145a7feeec4707d7461948c13bed0ff5822579101e111ca70602c17b4e0
7
- data.tar.gz: 67ae52cb1a8c87ecbf74f4c3ab110985a2c6f7596e41bb6bbb8b26bf0ad968767113eb367fe1473a6fab2cec03528db9dda099b526f1d4c5b5c70593e24474b5
6
+ metadata.gz: c517e0bb01fa40490b5e6cbe0c0919f8b03fb384835abb48867dd2bb4bdba3091b55be6a77cedc5ce8463d2c4de80c01121c6b99825a3fd6edb5eb4430de6182
7
+ data.tar.gz: 96e82346f38c78e07cbaa1a059dbc374d9c5c5dab11c4d080d1f497c2902b64960c848e82e4c4b2946ed592251830b4996b60083e5805e8cb88c0a9f0201f7b8
data/README.md CHANGED
@@ -26,7 +26,48 @@ and then there is the one and only command available
26
26
 
27
27
  Puertos.fetch
28
28
 
29
- returns the swell and wind data for the next 72 hours
29
+ returns the swell and wind data for the next 72 hours, as an ForecastData array
30
+
31
+ ForecastData has the following methods:
32
+
33
+ forecast_data_instance.timestamp
34
+
35
+ returns the time of the forecast as a Time object
36
+
37
+ forecast_data_instance.wind
38
+
39
+ returns a Puertos::WindData object, for which the following methods are available
40
+
41
+ wind_data_instance.speed => "3.4"
42
+ wind_data_instance.direction => "SSE"
43
+ wind_data_instance.unit => "m/s"
44
+
45
+ forecast_data_instance.total_swell
46
+
47
+ returns a Puertos::SwellData object, which has the sum of all swells.
48
+
49
+ forecast_data_instance.wind_swell
50
+
51
+ returns a Puertos::SwellData object, which represent the swell generated by nearby winds
52
+
53
+ forecast_data_instance.ground_swell_1
54
+
55
+ returns a Puertos::SwellData object, with the primary ground swell data
56
+
57
+ forecast_data_instance.ground_swell_1
58
+
59
+ returns a Puertos::SwellData object, with the secondary ground swell data
60
+
61
+
62
+ For every SwellData object, following methods are available
63
+
64
+ wind_data_instance.height => "3.4"
65
+ wind_data_instance.height_unit => "m"
66
+ wind_data_instance.direction => "NNW"
67
+ wind_data_instance.avg_period => "8"
68
+ wind_data_instance.peak_period => "10"
69
+ wind_data_instance.period_unit => "s"
70
+
30
71
 
31
72
 
32
73
  ## Contributing
@@ -1,3 +1,3 @@
1
1
  module Puertos
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/row_parser.rb CHANGED
@@ -5,49 +5,53 @@ module Puertos
5
5
  class RowParser
6
6
 
7
7
  attr_reader :row
8
-
8
+
9
9
  def initialize row
10
10
  @row = row
11
11
  end
12
12
 
13
13
  def run
14
- timestamp = read_column(1)
14
+ timestamp = create_timestamp
15
15
  wind = create_wind_data
16
16
  total_swell = create_total_swell_data
17
17
  wind_swell = create_wind_swell_data
18
18
  ground_swell_1 = create_ground_swell_data_1
19
19
  ground_swell_2 = create_ground_swell_data_2
20
20
 
21
- ForecastData.new wind, total_swell, wind_swell, ground_swell_1, ground_swell_2
21
+ ForecastData.new timestamp, wind, total_swell, wind_swell, ground_swell_1, ground_swell_2
22
22
  end
23
23
 
24
24
  private
25
25
 
26
+ def create_timestamp
27
+ Time.parse read_column(1)
28
+ end
29
+
26
30
  def create_wind_data
27
- Puertos::WindData.new speed: read_column(5), direction: read_column(6)
31
+ Puertos::WindData.new speed: read_column(4), direction: read_column(5)
28
32
  end
29
33
 
30
34
  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)
35
+ Puertos::SwellData.new height: read_column(6), direction: read_column(7), avg_period: read_column(9), peak_period: read_column(8)
32
36
  end
33
37
 
34
38
  def create_wind_swell_data
35
- Puertos::SwellData.new height: read_column(11), direction: read_column(12)
39
+ Puertos::SwellData.new height: read_column(10), direction: read_column(11)
36
40
  end
37
41
 
38
42
  def create_ground_swell_data_1
39
- Puertos::SwellData.new height: read_column(13), direction: read_column(14), avg_period: read_column(15)
43
+ Puertos::SwellData.new height: read_column(12), direction: read_column(13), avg_period: read_column(14)
40
44
  end
41
45
 
42
46
  def create_ground_swell_data_2
43
- Puertos::SwellData.new height: read_column(16), direction: read_column(17), avg_period: read_column(18)
47
+ Puertos::SwellData.new height: read_column(15), direction: read_column(16), avg_period: read_column(17)
44
48
  end
45
49
 
46
50
  def read_column number
47
- row.css("td:nth-child(#{number})").text
51
+ row.css("td:nth-child(#{number})").text.strip
48
52
  end
49
53
  end
50
54
 
51
- class ForecastData < Struct.new :wind, :total_swell, :wind_swell, :ground_swell_1, :ground_swell_2
55
+ class ForecastData < Struct.new :timestamp, :wind, :total_swell, :wind_swell, :ground_swell_1, :ground_swell_2
52
56
  end
53
57
  end
data/lib/swell_data.rb CHANGED
@@ -1,11 +1,15 @@
1
1
  module Puertos
2
2
  class SwellData
3
- #remove after upgrading to ruby 2.1
4
- def initialize(height: 1, direction: 'e', avg_period: nil, peak_period: nil)
3
+
4
+ attr_reader :height, :height_unit, :direction, :avg_period, :peak_period, :period_unit
5
+
6
+ def initialize(height: nil, height_unit: 'm', direction: nil, avg_period: nil, peak_period: nil, period_unit: 's')
5
7
  @height = height
8
+ @height_unit = height_unit
6
9
  @direction = direction
7
10
  @avg_period = avg_period
8
11
  @peak_period = peak_period
12
+ @period_unit = period_unit
9
13
  end
10
14
  end
11
15
  end
data/lib/wind_data.rb CHANGED
@@ -1,9 +1,11 @@
1
1
  module Puertos
2
2
  class WindData
3
- #remove after upgrading to ruby 2.1
4
- def initialize(speed: 1, direction: 'e')
3
+ attr_reader :speed, :direction, :unit
4
+
5
+ def initialize(speed: nil, direction: nil, unit: 'm/s')
5
6
  @speed = speed
6
7
  @direction = direction
8
+ @unit = unit
7
9
  end
8
10
  end
9
11
  end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe Puertos::RowParser do
4
+ let(:row) do
5
+ Nokogiri::HTML(open(Puertos::Parser::DATA_URL)).css(Puertos::Parser::CSS_ROWS_SELECTOR).last
6
+ end
7
+
8
+ let(:subject) { Puertos::RowParser.new row }
9
+
10
+ describe '#run' do
11
+ let(:forecast) { subject.run }
12
+
13
+ it 'has a proper timestamp' do
14
+ expect(forecast.timestamp).to be_a Time
15
+ end
16
+
17
+ it 'has wind data' do
18
+ expect(forecast.wind).to be_a Puertos::WindData
19
+ end
20
+
21
+ it 'has total swell data' do
22
+ expect(forecast.total_swell).to be_a Puertos::SwellData
23
+ end
24
+
25
+ it 'has wind swell data' do
26
+ expect(forecast.wind_swell).to be_a Puertos::SwellData
27
+ end
28
+
29
+ it 'has ground swell data' do
30
+ expect(forecast.ground_swell_1).to be_a Puertos::SwellData
31
+ end
32
+
33
+ it 'has secondary swell data' do
34
+ expect(forecast.ground_swell_2).to be_a Puertos::SwellData
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe Puertos::SwellData do
4
+ let(:subject) { Puertos::SwellData.new height: '3', direction: 'E', avg_period: '3', peak_period: '5'}
5
+
6
+ describe '#height' do
7
+ it 'returns the swell height' do
8
+ expect(subject.height).to eq '3'
9
+ end
10
+ end
11
+
12
+ describe '#height_unit' do
13
+ it 'returns the swell height_unit' do
14
+ expect(subject.height_unit).to eq 'm'
15
+ end
16
+ end
17
+
18
+ describe '#direction' do
19
+ it 'returns the swell direction' do
20
+ expect(subject.direction).to eq 'E'
21
+ end
22
+ end
23
+
24
+ describe '#avg_period' do
25
+ it 'returns the swell avg_period' do
26
+ expect(subject.avg_period).to eq '3'
27
+ end
28
+ end
29
+
30
+ describe '#peak_period' do
31
+ it 'returns the swell peak_period' do
32
+ expect(subject.peak_period).to eq '5'
33
+ end
34
+ end
35
+
36
+ describe '#period_unit' do
37
+ it 'returns the swell period_unit' do
38
+ expect(subject.period_unit).to eq 's'
39
+ end
40
+ end
41
+
42
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe Puertos::WindData do
4
+ let(:subject) { Puertos::WindData.new speed: '2.3', direction: 'E' }
5
+
6
+ describe '#speed' do
7
+ it 'returns the wind speed' do
8
+ expect(subject.speed).to eq '2.3'
9
+ end
10
+ end
11
+
12
+ describe '#direction' do
13
+ it 'returns the wind direction' do
14
+ expect(subject.direction).to eq 'E'
15
+ end
16
+ end
17
+
18
+ describe '#unit' do
19
+ it 'returns the wind unit' do
20
+ expect(subject.unit).to eq 'm/s'
21
+ end
22
+ end
23
+
24
+ end
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puertos
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - rgalindo33
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-11 00:00:00.000000000 Z
11
+ date: 2015-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.5'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: nokogiri
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  description: returns ruby objects with meaningfull swell data
@@ -59,7 +59,7 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
- - .gitignore
62
+ - ".gitignore"
63
63
  - Gemfile
64
64
  - Guardfile
65
65
  - LICENSE.txt
@@ -73,7 +73,10 @@ files:
73
73
  - lib/wind_data.rb
74
74
  - puertos.gemspec
75
75
  - spec/puertos_spec.rb
76
+ - spec/row_parser_spec.rb
76
77
  - spec/spec_helper.rb
78
+ - spec/swell_data_spec.rb
79
+ - spec/wind_data_spec.rb
77
80
  homepage: https://github.com/rgalindo33/puertos
78
81
  licenses:
79
82
  - MIT
@@ -84,12 +87,12 @@ require_paths:
84
87
  - lib
85
88
  required_ruby_version: !ruby/object:Gem::Requirement
86
89
  requirements:
87
- - - '>='
90
+ - - ">="
88
91
  - !ruby/object:Gem::Version
89
92
  version: '0'
90
93
  required_rubygems_version: !ruby/object:Gem::Requirement
91
94
  requirements:
92
- - - '>='
95
+ - - ">="
93
96
  - !ruby/object:Gem::Version
94
97
  version: '0'
95
98
  requirements: []
@@ -100,4 +103,7 @@ specification_version: 4
100
103
  summary: Forecast swell information for Barcelona
101
104
  test_files:
102
105
  - spec/puertos_spec.rb
106
+ - spec/row_parser_spec.rb
103
107
  - spec/spec_helper.rb
108
+ - spec/swell_data_spec.rb
109
+ - spec/wind_data_spec.rb