wasserstand 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .cache_rake_t
@@ -2,6 +2,7 @@ require 'nokogiri'
2
2
  require 'open-uri'
3
3
  require 'tzinfo'
4
4
  require 'unicode_utils/upcase'
5
+ require 'unicode_utils/downcase'
5
6
 
6
7
  require 'require_all'
7
8
  require_rel 'wasserstand'
@@ -30,9 +30,9 @@ module Wasserstand
30
30
 
31
31
  messdatum = TZInfo::Timezone.get('Europe/Berlin').local_to_utc(Time.parse("#{datum} #{uhrzeit}"))
32
32
  wert = item.xpath('messwert').text.sub(',', '.').to_f
33
- tendenz = item.xpath('tendenz').text.downcase.to_sym
33
+ tendenz = item.xpath('tendenz').text
34
34
 
35
- pegel.measurements << Measurement.new(messdatum, wert, tendenz)
35
+ pegel.measurements << Measurement.new(messdatum, wert, Trend.new(tendenz))
36
36
  end
37
37
  end
38
38
  end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ module Wasserstand
3
+ # http://blog.steveklabnik.com/posts/2012-09-09-random-ruby-tricks--class-new
4
+ IllegalValueError = Class.new(StandardError)
5
+
6
+ class Trend
7
+ def initialize(value)
8
+ @value = {'gleich' => :gleichbleibend,
9
+ 'steigend' => :steigend,
10
+ 'fallend' => :fallend}[UnicodeUtils.downcase(value.to_s)]
11
+
12
+ raise IllegalValueError, "Unknown trend #{value.inspect}" unless @value
13
+ end
14
+
15
+ def symbol
16
+ {:gleichbleibend => '⬄', :steigend => '⬀', :fallend => '⬂'}[@value]
17
+ end
18
+
19
+ def to_s
20
+ @value.to_s
21
+ end
22
+ end
23
+ end
@@ -1,3 +1,3 @@
1
1
  module Wasserstand
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -4,8 +4,8 @@ class TestMeasurement < WasserstandTestCase
4
4
  def test_single
5
5
  konstanz_measurements = Waterway['BODENSEE'].levels['KONSTANZ'].measurements
6
6
 
7
+ assert_equal(1, konstanz_measurements.size)
7
8
  assert_equal(Time.parse('2012-09-13 18:00:00 UTC'), konstanz_measurements.last.date)
8
9
  assert_equal(380.7, konstanz_measurements.last.value)
9
- assert_equal(:gleich, konstanz_measurements.last.trend)
10
10
  end
11
11
  end
@@ -0,0 +1,59 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestTrend < WasserstandTestCase
5
+
6
+ def test_create_unknown
7
+ assert_raises(ArgumentError){Trend.new}
8
+ assert_raises(IllegalValueError){Trend.new(nil)}
9
+ assert_raises(IllegalValueError){Trend.new('foobar')}
10
+ assert_raises(IllegalValueError){Trend.new(:foobar)}
11
+ end
12
+
13
+ def test_create_gleich
14
+ assert_trend_gleich(Trend.new('gleich'))
15
+ assert_trend_gleich(Trend.new('Gleich'))
16
+ assert_trend_gleich(Trend.new('GLEICH'))
17
+ assert_trend_gleich(Trend.new(:gleich))
18
+ end
19
+
20
+ def test_create_steigend
21
+ assert_trend_steigend(Trend.new('steigend'))
22
+ assert_trend_steigend(Trend.new('Steigend'))
23
+ assert_trend_steigend(Trend.new('STEIGEND'))
24
+ assert_trend_steigend(Trend.new(:steigend))
25
+ end
26
+
27
+ def test_create_fallend
28
+ assert_trend_fallend(Trend.new('fallend'))
29
+ assert_trend_fallend(Trend.new('Fallend'))
30
+ assert_trend_fallend(Trend.new('FALLEND'))
31
+ assert_trend_fallend(Trend.new(:fallend))
32
+ end
33
+
34
+ def test_mapped
35
+ assert_trend_gleich(Waterway['BODENSEE'].levels['KONSTANZ'].measurements.last.trend)
36
+ assert_trend_steigend(Waterway['Oder'].levels['SCHWEDT-ODERBRÜCKE'].measurements.last.trend)
37
+ assert_trend_fallend(Waterway['Elbe'].levels['STADERSAND'].measurements.last.trend)
38
+ end
39
+
40
+ private
41
+
42
+ def assert_trend_gleich(trend)
43
+ assert(trend)
44
+ assert_equal('⬄', trend.symbol)
45
+ assert_equal('gleichbleibend', trend.to_s)
46
+ end
47
+
48
+ def assert_trend_fallend(trend)
49
+ assert(trend)
50
+ assert_equal('⬂', trend.symbol)
51
+ assert_equal('fallend', trend.to_s)
52
+ end
53
+
54
+ def assert_trend_steigend(trend)
55
+ assert(trend)
56
+ assert_equal('⬀', trend.symbol)
57
+ assert_equal('steigend', trend.to_s)
58
+ end
59
+ 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.6
4
+ version: 0.0.7
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-17 00:00:00.000000000 Z
12
+ date: 2012-09-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: require_all
@@ -128,12 +128,14 @@ files:
128
128
  - lib/wasserstand/provider/level_mapper.rb
129
129
  - lib/wasserstand/provider/pegel-online.rb
130
130
  - lib/wasserstand/provider/waterway_mapper.rb
131
+ - lib/wasserstand/trend.rb
131
132
  - lib/wasserstand/version.rb
132
133
  - lib/wasserstand/waterway.rb
133
134
  - test/fixtures/pegelstaende_neu.xml
134
135
  - test/helper.rb
135
136
  - test/unit/test_level.rb
136
137
  - test/unit/test_measurement.rb
138
+ - test/unit/test_trend.rb
137
139
  - test/unit/test_waterway.rb
138
140
  - wasserstand.gemspec
139
141
  homepage: http://github.com/nerab/wasserstand
@@ -165,4 +167,5 @@ test_files:
165
167
  - test/helper.rb
166
168
  - test/unit/test_level.rb
167
169
  - test/unit/test_measurement.rb
170
+ - test/unit/test_trend.rb
168
171
  - test/unit/test_waterway.rb