wasserstand 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,14 +9,8 @@ require_rel 'wasserstand'
9
9
 
10
10
  module Wasserstand
11
11
  class << self
12
- attr_writer :waterway_provider, :level_provider
13
-
14
- def waterway_provider
15
- @waterway_provider ||= PegelOnline::WaterwayProvider.new
16
- end
17
-
18
- def level_provider
19
- @level_provider ||= PegelOnline::LevelProvider.new
12
+ def providers
13
+ @providers ||= Hash.new{|hash, k| hash[k] = k.new}
20
14
  end
21
15
  end
22
16
  end
@@ -5,15 +5,21 @@ module Wasserstand
5
5
  class Level # Pegel
6
6
  class << self
7
7
  def [](name)
8
- Wasserstand.level_provider[name]
8
+ provider[name]
9
9
  end
10
10
 
11
11
  def all
12
- Wasserstand.level_provider.all
12
+ provider.all
13
13
  end
14
14
 
15
15
  def find_by_name(regex)
16
- Wasserstand.level_provider.find_by_name(regex)
16
+ provider.find_by_name(regex)
17
+ end
18
+
19
+ private
20
+
21
+ def provider
22
+ Wasserstand.providers[PegelOnline::LevelProvider]
17
23
  end
18
24
  end
19
25
 
@@ -45,6 +45,7 @@ module Wasserstand
45
45
  end
46
46
 
47
47
  def fetch(url)
48
+ STDERR.puts "FETCH #{url}"
48
49
  open(url).read
49
50
  end
50
51
 
@@ -5,15 +5,19 @@ module Wasserstand
5
5
 
6
6
  class Trend
7
7
  def initialize(value)
8
- @value = {'gleich' => :gleichbleibend,
9
- 'steigend' => :steigend,
10
- 'fallend' => :fallend}[UnicodeUtils.downcase(value.to_s)]
8
+ @value = {'gleich' => :gleichbleibend,
9
+ 'steigend' => :steigend,
10
+ 'fallend' => :fallend,
11
+ 'unbekannt' => :unbekannt}[UnicodeUtils.downcase(value.to_s)]
11
12
 
12
13
  raise IllegalValueError, "Unknown trend #{value.inspect}" unless @value
13
14
  end
14
15
 
15
16
  def symbol
16
- {:gleichbleibend => '⬄', :steigend => '⬀', :fallend => '⬂'}[@value]
17
+ {:gleichbleibend => '⬄',
18
+ :steigend => '⬀',
19
+ :fallend => '⬂',
20
+ :unbekannt => '?'}[@value]
17
21
  end
18
22
 
19
23
  def to_s
@@ -1,3 +1,3 @@
1
1
  module Wasserstand
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -13,15 +13,21 @@ module Wasserstand
13
13
  class Waterway
14
14
  class << self
15
15
  def [](name)
16
- Wasserstand.waterway_provider[name]
16
+ provider[name]
17
17
  end
18
18
 
19
19
  def all
20
- Wasserstand.waterway_provider.all
20
+ provider.all
21
21
  end
22
22
 
23
23
  def find_by_name(regex)
24
- Wasserstand.waterway_provider.find_by_name(regex)
24
+ provider.find_by_name(regex)
25
+ end
26
+
27
+ private
28
+
29
+ def provider
30
+ Wasserstand.providers[PegelOnline::WaterwayProvider]
25
31
  end
26
32
  end
27
33
 
@@ -5203,7 +5203,7 @@
5203
5203
  <messwert>137</messwert>
5204
5204
  <km>27,9</km>
5205
5205
  <pnp>54,666</pnp>
5206
- <tendenz>Gleich</tendenz>
5206
+ <tendenz>Unbekannt</tendenz>
5207
5207
  <datum>13.09.2012</datum>
5208
5208
  <uhrzeit>05:00:00</uhrzeit>
5209
5209
  <pegelnummer>579100</pegelnummer>
@@ -6,7 +6,7 @@ class WasserstandTestCase < MiniTest::Unit::TestCase
6
6
 
7
7
  def setup
8
8
  url = File.join(File.dirname(__FILE__), 'fixtures', 'pegelstaende_neu.xml')
9
- Wasserstand.waterway_provider = PegelOnline::WaterwayProvider.new(url)
10
- Wasserstand.level_provider = PegelOnline::LevelProvider.new(url)
9
+ Wasserstand.providers[PegelOnline::WaterwayProvider] = PegelOnline::WaterwayProvider.new(url)
10
+ Wasserstand.providers[PegelOnline::LevelProvider] = PegelOnline::LevelProvider.new(url)
11
11
  end
12
12
  end
@@ -3,7 +3,7 @@ require 'helper'
3
3
 
4
4
  class TestTrend < WasserstandTestCase
5
5
 
6
- def test_create_unknown
6
+ def test_create_illegal
7
7
  assert_raises(ArgumentError){Trend.new}
8
8
  assert_raises(IllegalValueError){Trend.new(nil)}
9
9
  assert_raises(IllegalValueError){Trend.new('foobar')}
@@ -31,10 +31,18 @@ class TestTrend < WasserstandTestCase
31
31
  assert_trend_fallend(Trend.new(:fallend))
32
32
  end
33
33
 
34
+ def test_create_unbekannt
35
+ assert_trend_unbekannt(Trend.new('unbekannt'))
36
+ assert_trend_unbekannt(Trend.new('Unbekannt'))
37
+ assert_trend_unbekannt(Trend.new('UNBEKANNT'))
38
+ assert_trend_unbekannt(Trend.new(:unbekannt))
39
+ end
40
+
34
41
  def test_mapped
35
42
  assert_trend_gleich(Waterway['BODENSEE'].levels['KONSTANZ'].measurements.last.trend)
36
43
  assert_trend_steigend(Waterway['Oder'].levels['SCHWEDT-ODERBRÜCKE'].measurements.last.trend)
37
44
  assert_trend_fallend(Waterway['Elbe'].levels['STADERSAND'].measurements.last.trend)
45
+ assert_trend_unbekannt(Waterway['Saale'].levels['Nienburg'].measurements.last.trend)
38
46
  end
39
47
 
40
48
  private
@@ -56,4 +64,10 @@ class TestTrend < WasserstandTestCase
56
64
  assert_equal('⬀', trend.symbol)
57
65
  assert_equal('steigend', trend.to_s)
58
66
  end
67
+
68
+ def assert_trend_unbekannt(trend)
69
+ assert(trend)
70
+ assert_equal('?', trend.symbol)
71
+ assert_equal('unbekannt', trend.to_s)
72
+ end
59
73
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wasserstand
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
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: 2012-09-18 00:00:00.000000000 Z
12
+ date: 2012-09-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: require_all