wasserstand 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/wasserstand.rb +2 -8
- data/lib/wasserstand/level.rb +9 -3
- data/lib/wasserstand/provider/pegel-online.rb +1 -0
- data/lib/wasserstand/trend.rb +8 -4
- data/lib/wasserstand/version.rb +1 -1
- data/lib/wasserstand/waterway.rb +9 -3
- data/test/fixtures/pegelstaende_neu.xml +1 -1
- data/test/helper.rb +2 -2
- data/test/unit/test_trend.rb +15 -1
- metadata +2 -2
data/lib/wasserstand.rb
CHANGED
@@ -9,14 +9,8 @@ require_rel 'wasserstand'
|
|
9
9
|
|
10
10
|
module Wasserstand
|
11
11
|
class << self
|
12
|
-
|
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
|
data/lib/wasserstand/level.rb
CHANGED
@@ -5,15 +5,21 @@ module Wasserstand
|
|
5
5
|
class Level # Pegel
|
6
6
|
class << self
|
7
7
|
def [](name)
|
8
|
-
|
8
|
+
provider[name]
|
9
9
|
end
|
10
10
|
|
11
11
|
def all
|
12
|
-
|
12
|
+
provider.all
|
13
13
|
end
|
14
14
|
|
15
15
|
def find_by_name(regex)
|
16
|
-
|
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
|
|
data/lib/wasserstand/trend.rb
CHANGED
@@ -5,15 +5,19 @@ module Wasserstand
|
|
5
5
|
|
6
6
|
class Trend
|
7
7
|
def initialize(value)
|
8
|
-
@value = {'gleich'
|
9
|
-
'steigend'
|
10
|
-
'fallend'
|
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 => '⬄',
|
17
|
+
{:gleichbleibend => '⬄',
|
18
|
+
:steigend => '⬀',
|
19
|
+
:fallend => '⬂',
|
20
|
+
:unbekannt => '?'}[@value]
|
17
21
|
end
|
18
22
|
|
19
23
|
def to_s
|
data/lib/wasserstand/version.rb
CHANGED
data/lib/wasserstand/waterway.rb
CHANGED
@@ -13,15 +13,21 @@ module Wasserstand
|
|
13
13
|
class Waterway
|
14
14
|
class << self
|
15
15
|
def [](name)
|
16
|
-
|
16
|
+
provider[name]
|
17
17
|
end
|
18
18
|
|
19
19
|
def all
|
20
|
-
|
20
|
+
provider.all
|
21
21
|
end
|
22
22
|
|
23
23
|
def find_by_name(regex)
|
24
|
-
|
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
|
|
data/test/helper.rb
CHANGED
@@ -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.
|
10
|
-
Wasserstand.
|
9
|
+
Wasserstand.providers[PegelOnline::WaterwayProvider] = PegelOnline::WaterwayProvider.new(url)
|
10
|
+
Wasserstand.providers[PegelOnline::LevelProvider] = PegelOnline::LevelProvider.new(url)
|
11
11
|
end
|
12
12
|
end
|
data/test/unit/test_trend.rb
CHANGED
@@ -3,7 +3,7 @@ require 'helper'
|
|
3
3
|
|
4
4
|
class TestTrend < WasserstandTestCase
|
5
5
|
|
6
|
-
def
|
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.
|
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-
|
12
|
+
date: 2012-09-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: require_all
|