skiplan_client 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,6 +9,10 @@ class Forecast
9
9
  self.attributes = attributes
10
10
  end
11
11
 
12
+ def updated_at
13
+ @datemaj
14
+ end
15
+
12
16
  def weather_am
13
17
  @CIEL_ID
14
18
  end
@@ -5,9 +5,9 @@ class Metrics
5
5
 
6
6
  include AttributeHelper
7
7
 
8
- METRICS = ['SKI_ALPIN', 'SKI_ALPIN_VERTES', 'SKI_ALPIN_BLEUES', 'SKI_ALPIN_ROUGES', 'SKI_ALPIN_NOIRES',
8
+ METRICS = ['SKI_NUIT', 'KM_SKATING', 'SKI_ALPIN', 'SKI_ALPIN_VERTES', 'SKI_ALPIN_BLEUES', 'SKI_ALPIN_ROUGES', 'SKI_ALPIN_NOIRES',
9
9
  'SKI_NORDIQUE', 'SKI_NORDIQUE_VERTES', 'SKI_NORDIQUE_BLEUES', 'SKI_NORDIQUE_ROUGES', 'SKI_NORDIQUE_NOIRES',
10
- 'PIETONS', 'RAQUETTES', 'LUGE', 'SNOWPARK']
10
+ 'REMONTEES', 'PIETONS', 'RAQUETTES', 'LUGE', 'SNOWPARK']
11
11
 
12
12
  def initialize(attributes)
13
13
  self.attributes = attributes.keep_if {|k, v| METRICS.include?(k)} unless attributes.nil?
@@ -51,6 +51,18 @@ class Metrics
51
51
  {:total => get_ratio(@SNOWPARK)}
52
52
  end
53
53
 
54
+ def skilifts
55
+ {:total => get_ratio(@REMONTEES)}
56
+ end
57
+
58
+ def night_ski
59
+ @SKI_NUIT && @SKI_NUIT['etat'] == '1'
60
+ end
61
+
62
+ def skating
63
+ @KM_SKATING['ouvert'] unless @KM_SKATING.nil?
64
+ end
65
+
54
66
  private
55
67
 
56
68
  def get_ratio(hash)
@@ -0,0 +1,9 @@
1
+ class Skiplan
2
+
3
+ attr_accessor :forecasts, :metrics, :zones
4
+
5
+ def initialize
6
+ @forecasts = {}
7
+ @zones = {}
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module SkiplanClient
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -0,0 +1,27 @@
1
+ require 'skiplan_client/attribute_helper'
2
+
3
+ class Zone
4
+
5
+ include AttributeHelper
6
+
7
+ def initialize(attributes)
8
+ self.attributes = attributes
9
+ end
10
+
11
+ def name
12
+ @nom
13
+ end
14
+
15
+ def skilifts
16
+ @REMONTEE
17
+ end
18
+
19
+ def slopes
20
+ @PISTE
21
+ end
22
+
23
+ def ratio(array_field = [])
24
+ open_entries = array_field.select {|r| r['etat'] == 'O'}
25
+ "#{open_entries.length}/#{array_field.length}"
26
+ end
27
+ end
@@ -1,6 +1,7 @@
1
1
  require 'skiplan_client/version'
2
2
  require 'skiplan_client/forecast'
3
3
  require 'skiplan_client/metrics'
4
+ require 'skiplan_client/zone'
4
5
  require 'open-uri'
5
6
  require 'nokogiri'
6
7
  require 'active_support/core_ext/hash/conversions'
@@ -18,7 +19,7 @@ module SkiplanClient
18
19
 
19
20
  def self.get_weather(zone)
20
21
  xml = Nokogiri::XML(open(@config[:base_url]))
21
- weather = WeatherObject.new
22
+ weather = Skiplan.new
22
23
 
23
24
  today_element = xml.xpath('//ZONE[@nom="' + zone + '"]')
24
25
  weather.forecasts['j'] = Forecast.new(Hash.from_xml(today_element.to_s)['ZONE'])
@@ -35,6 +36,11 @@ module SkiplanClient
35
36
  metrics = xml.xpath('//INDICES')
36
37
  weather.metrics = Metrics.new(Hash.from_xml(metrics.to_s)['INDICES'])
37
38
 
39
+ zones = xml.xpath('//SECTEUR')
40
+ zones.each do |z|
41
+ weather.zones[z['nom']] = Zone.new(Hash.from_xml(z.to_s)['SECTEUR'])
42
+ end
43
+
38
44
  weather
39
45
  end
40
46
  end
@@ -8,19 +8,21 @@ require 'skiplan_client/forecast'
8
8
  class ForecastTest < Test::Unit::TestCase
9
9
 
10
10
  should 'populate forecast with attributes values' do
11
- forecast = Forecast.new({'TEMPERATURE' => '+10',
12
- 'TEMPERATURE_APM' => '+14',
13
- 'TEMPERATURE_RESSENTIE' => '+4',
14
- 'VENT' => '4',
15
- 'DIRECTION' => 'S',
16
- 'CIEL_ID' => '101',
17
- 'CIEL_ID_APM' => '101',
18
- 'VALRISQUE' => '3',
19
- 'CUMUL' => '100',
20
- 'NEIGE' => '20',
21
- 'DERNIERE_CHUTE' => '22/04/2014 08:31',
22
- 'VISIBILITE' => '100'})
11
+ forecast = Forecast.new({'datemaj' => '03/07/2014 17:01:18',
12
+ 'TEMPERATURE' => '+10',
13
+ 'TEMPERATURE_APM' => '+14',
14
+ 'TEMPERATURE_RESSENTIE' => '+4',
15
+ 'VENT' => '4',
16
+ 'DIRECTION' => 'S',
17
+ 'CIEL_ID' => '101',
18
+ 'CIEL_ID_APM' => '101',
19
+ 'VALRISQUE' => '3',
20
+ 'CUMUL' => '100',
21
+ 'NEIGE' => '20',
22
+ 'DERNIERE_CHUTE' => '22/04/2014 08:31',
23
+ 'VISIBILITE' => '100'})
23
24
 
25
+ assert_equal '03/07/2014 17:01:18', forecast.updated_at
24
26
  assert_equal '101', forecast.weather_am
25
27
  assert_equal '101', forecast.weather_pm
26
28
  assert_equal '+10', forecast.temp_am
@@ -8,7 +8,9 @@ require 'skiplan_client/metrics'
8
8
  class MetricsTest < Test::Unit::TestCase
9
9
 
10
10
  setup do
11
- attributes = {'SKI_ALPIN'=>{'total'=>'44', 'total_periode'=>'44', 'total_periode_hpf'=>'44', 'ouvertes_previsions'=>'0', 'ouvertes'=>'10', 'previsions'=>'0', 'fermees'=>'44', 'lng_total'=>'0.0', 'lng_ouverts'=>'0.0'},
11
+ attributes = {'SKI_NUIT' => {'etat' => '1'},
12
+ 'KM_SKATING' => {'ouvert' => '10'},
13
+ 'SKI_ALPIN'=>{'total'=>'44', 'total_periode'=>'44', 'total_periode_hpf'=>'44', 'ouvertes_previsions'=>'0', 'ouvertes'=>'10', 'previsions'=>'0', 'fermees'=>'44', 'lng_total'=>'0.0', 'lng_ouverts'=>'0.0'},
12
14
  'SKI_ALPIN_VERTES'=>{'total'=>'12', 'total_periode'=>'12', 'total_periode_hpf'=>'12', 'ouvertes_previsions'=>'0', 'ouvertes'=>'2', 'previsions'=>'0', 'fermees'=>'12', 'lng_total'=>'0.0', 'lng_ouverts'=>'0.0'},
13
15
  'SKI_ALPIN_BLEUES'=>{'total'=>'15', 'total_periode'=>'15', 'total_periode_hpf'=>'15', 'ouvertes_previsions'=>'0', 'ouvertes'=>'3', 'previsions'=>'0', 'fermees'=>'15', 'lng_total'=>'0.0', 'lng_ouverts'=>'0.0'},
14
16
  'SKI_ALPIN_ROUGES'=>{'total'=>'14', 'total_periode'=>'14', 'total_periode_hpf'=>'14', 'ouvertes_previsions'=>'0', 'ouvertes'=>'4', 'previsions'=>'0', 'fermees'=>'14', 'lng_total'=>'0.0', 'lng_ouverts'=>'0.0'},
@@ -18,6 +20,7 @@ class MetricsTest < Test::Unit::TestCase
18
20
  'SKI_NORDIQUE_BLEUES'=>{'total'=>'4', 'total_periode'=>'4', 'total_periode_hpf'=>'4', 'ouvertes_previsions'=>'0', 'ouvertes'=>'3', 'previsions'=>'0', 'fermees'=>'4', 'lng_total'=>'20.9', 'lng_ouverts'=>'0.0'},
19
21
  'SKI_NORDIQUE_ROUGES'=>{'total'=>'3', 'total_periode'=>'3', 'total_periode_hpf'=>'3', 'ouvertes_previsions'=>'0', 'ouvertes'=>'1', 'previsions'=>'0', 'fermees'=>'3', 'lng_total'=>'18.5', 'lng_ouverts'=>'0.0'},
20
22
  'SKI_NORDIQUE_NOIRES'=>{'total'=>'3', 'total_periode'=>'3', 'total_periode_hpf'=>'3', 'ouvertes_previsions'=>'0', 'ouvertes'=>'0', 'previsions'=>'0', 'fermees'=>'3', 'lng_total'=>'22.6', 'lng_ouverts'=>'0.0'},
23
+ 'REMONTEES' => {'total'=>'32', 'total_periode'=>'32', 'total_periode_hpf'=>'32', 'ouvertes_previsions'=>'0', 'ouvertes'=>'0', 'previsions'=>'0', 'fermees'=>'32'},
21
24
  'PIETONS'=>{'total'=>'12', 'total_periode'=>'12', 'total_periode_hpf'=>'12', 'ouvertes_previsions'=>'9', 'ouvertes'=>'9', 'previsions'=>'0', 'fermees'=>'3', 'lng_total'=>'47.5', 'lng_ouverts'=>'35.0'},
22
25
  'RAQUETTES'=>{'total'=>'14', 'total_periode'=>'14', 'total_periode_hpf'=>'14', 'ouvertes_previsions'=>'0', 'ouvertes'=>'1', 'previsions'=>'0', 'fermees'=>'14', 'lng_total'=>'61.0', 'lng_ouverts'=>'0.0'},
23
26
  'LUGE'=>{'total'=>'4', 'total_periode'=>'4', 'total_periode_hpf'=>'4', 'ouvertes_previsions'=>'0', 'ouvertes'=>'2', 'previsions'=>'0', 'fermees'=>'4', 'lng_total'=>'0.0', 'lng_ouverts'=>'0.0'},
@@ -71,4 +74,16 @@ class MetricsTest < Test::Unit::TestCase
71
74
  should 'return metrics for snowparks' do
72
75
  assert_equal '3/8', @metrics.snowpark[:total]
73
76
  end
77
+
78
+ should 'return metrics for skilifts' do
79
+ assert_equal '0/32', @metrics.skilifts[:total]
80
+ end
81
+
82
+ should 'return night ski availability for current day' do
83
+ assert_equal true, @metrics.night_ski
84
+ end
85
+
86
+ should 'return skating km available' do
87
+ assert_equal '10', @metrics.skating
88
+ end
74
89
  end
@@ -4,7 +4,7 @@ gem 'shoulda'
4
4
  require 'test/unit'
5
5
  require 'shoulda'
6
6
  require 'skiplan_client'
7
- require 'skiplan_client/weather_object'
7
+ require 'skiplan_client/skiplan'
8
8
 
9
9
  class SkiplanClientTest < Test::Unit::TestCase
10
10
 
@@ -53,12 +53,23 @@ class SkiplanClientTest < Test::Unit::TestCase
53
53
 
54
54
  assert_equal '0/44', metrics.alpine[:total]
55
55
  assert_equal '0/17', metrics.nordic[:total]
56
- assert_equal '9/12', metrics.pedestrian[:total]
57
- assert_equal '0/14', metrics.snowshoes[:total]
56
+ assert_equal '35/47.5km', metrics.pedestrian[:total]
57
+ assert_equal '0/61km', metrics.snowshoes[:total]
58
58
  assert_equal '0/4', metrics.sledge[:total]
59
59
  assert_equal '0/8', metrics.snowpark[:total]
60
60
  end
61
61
 
62
+ should 'retrieve zones data' do
63
+ SkiplanClient.configure('../../data/lumi_response.xml')
64
+ zones = SkiplanClient.get_weather('CHINAILLON').zones
65
+
66
+ assert_equal 10, zones.length
67
+ assert_equal 'ALPIN CHINAILLON', zones.keys[0]
68
+
69
+ ac_zone = zones['ALPIN CHINAILLON']
70
+ # assert_equal
71
+ end
72
+
62
73
  should 'change config url' do
63
74
  config = SkiplanClient.configure('my_new_url')
64
75
  assert_equal 'my_new_url', config
@@ -3,7 +3,7 @@ require 'rubygems'
3
3
  gem 'shoulda'
4
4
  require 'test/unit'
5
5
  require 'shoulda'
6
- require 'skiplan_client/weather_object'
6
+ require 'skiplan_client/skiplan'
7
7
 
8
8
  class WeatherObjectTest < Test::Unit::TestCase
9
9
 
@@ -0,0 +1,35 @@
1
+ # encoding : UTF-8
2
+ require 'rubygems'
3
+ gem 'shoulda'
4
+ require 'test/unit'
5
+ require 'shoulda'
6
+ require 'skiplan_client/zone'
7
+
8
+ class ZoneTest < Test::Unit::TestCase
9
+
10
+ setup do
11
+ attributes = {'nom' => 'ALPIN CHINAILLON',
12
+ 'REMONTEE' => [{'nom' => 'TS LA FLORIA', 'etat' => 'O', 'type' => 'TS', 'msg' => 'Fermee pour la saison'},
13
+ {'nom' => 'TK LE STADE', 'etat' => 'F', 'type' => 'TK', 'msg' => 'Fermee pour la saison'}],
14
+ 'PISTE' => [{'nom' => 'LA SERPENTINE', 'etat' => 'F', 'type' => 'A', 'msg' => '', 'niveau' => 'V'},
15
+ {'nom' => 'LE VENAY', 'etat' => 'O', 'type' => 'A', 'msg' => '', 'niveau' => 'V'}]
16
+ }
17
+ @zone = Zone.new(attributes)
18
+ end
19
+
20
+ should 'retrieve the data for a given zone' do
21
+ assert_equal 'ALPIN CHINAILLON', @zone.name
22
+ assert_equal [{'nom' => 'TS LA FLORIA', 'etat' => 'O', 'type' => 'TS', 'msg' => 'Fermee pour la saison'},
23
+ {'nom' => 'TK LE STADE', 'etat' => 'F', 'type' => 'TK', 'msg' => 'Fermee pour la saison'}], @zone.skilifts
24
+ assert_equal [{'nom' => 'LA SERPENTINE', 'etat' => 'F', 'type' => 'A', 'msg' => '', 'niveau' => 'V'},
25
+ {'nom' => 'LE VENAY', 'etat' => 'O', 'type' => 'A', 'msg' => '', 'niveau' => 'V'}], @zone.slopes
26
+ end
27
+
28
+ should 'return the ratio of open skilifts' do
29
+ assert_equal '1/2', @zone.ratio(@zone.skilifts)
30
+ end
31
+
32
+ should 'return the ratio of open slopes' do
33
+ assert_equal '1/2', @zone.ratio(@zone.slopes)
34
+ end
35
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skiplan_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-11-02 00:00:00.000000000 Z
12
+ date: 2014-11-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -124,13 +124,15 @@ files:
124
124
  - lib/skiplan_client/attribute_helper.rb
125
125
  - lib/skiplan_client/forecast.rb
126
126
  - lib/skiplan_client/metrics.rb
127
+ - lib/skiplan_client/skiplan.rb
127
128
  - lib/skiplan_client/version.rb
128
- - lib/skiplan_client/weather_object.rb
129
+ - lib/skiplan_client/zone.rb
129
130
  - skiplan_client.gemspec
130
131
  - test/skiplan_client/forecast_test.rb
131
132
  - test/skiplan_client/metrics_test.rb
132
133
  - test/skiplan_client/skiplan_client_test.rb
133
134
  - test/skiplan_client/weather_object_test.rb
135
+ - test/skiplan_client/zone_test.rb
134
136
  homepage: https://github.com/jeanbaptistevilain/skiplan_client
135
137
  licenses:
136
138
  - MIT
@@ -161,3 +163,4 @@ test_files:
161
163
  - test/skiplan_client/metrics_test.rb
162
164
  - test/skiplan_client/skiplan_client_test.rb
163
165
  - test/skiplan_client/weather_object_test.rb
166
+ - test/skiplan_client/zone_test.rb
@@ -1,8 +0,0 @@
1
- class WeatherObject
2
-
3
- attr_accessor :forecasts, :metrics
4
-
5
- def initialize
6
- @forecasts = {}
7
- end
8
- end