wasserstand 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -21,13 +21,17 @@ module Wasserstand
21
21
  def map(node)
22
22
  Waterway.new(node.xpath('name').text) .tap do |ww|
23
23
  node.xpath('item').each do |item|
24
- ww.level[name] = Level.new(item.xpath('pegelnummer').text).tap do |pegel|
25
- pegel.name = item.xpath('pegelname').text
24
+ pegel_name = item.xpath('pegelname').text
25
+ ww.levels[pegel_name] = Level.new(item.xpath('pegelnummer').text).tap do |pegel|
26
+ pegel.name = pegel_name
26
27
  pegel.km = item.xpath('km').text
27
28
 
28
- messdatum = Time.now # TODO parse date from date and time elements
29
- wert = item.xpath('messwert').text
30
- tendenz = item.xpath('tendenz').text
29
+ datum = item.xpath('datum').text
30
+ uhrzeit = item.xpath('uhrzeit').text
31
+
32
+ messdatum = Time.parse("#{datum} #{uhrzeit}")
33
+ wert = item.xpath('messwert').text.sub(',', '.').to_f
34
+ tendenz = item.xpath('tendenz').text.downcase.to_sym
31
35
 
32
36
  pegel.measurements << Measurement.new(messdatum, wert, tendenz)
33
37
  end
@@ -1,3 +1,3 @@
1
1
  module Wasserstand
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -6,11 +6,11 @@ module Wasserstand
6
6
  end
7
7
  end
8
8
 
9
- attr_reader :name, :level
9
+ attr_reader :name, :levels
10
10
 
11
11
  def initialize(name)
12
12
  @name = name
13
- @level = {}
13
+ @levels = {}
14
14
  end
15
15
  end
16
16
  end
data/lib/wasserstand.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'nokogiri'
2
2
  require 'open-uri'
3
+ require 'tzinfo'
3
4
 
4
5
  require 'require_all'
5
6
  require_rel 'wasserstand'
@@ -13,6 +13,19 @@ class TestWasserstand < MiniTest::Unit::TestCase
13
13
  end
14
14
 
15
15
  def test_levels
16
- assert_equal(1, Waterway['BODENSEE'].level.size)
16
+ assert_equal(1, Waterway['BODENSEE'].levels.size)
17
+ end
18
+
19
+ def test_level_lookup
20
+ assert(Waterway['BODENSEE'].levels['KONSTANZ'])
21
+ assert(Waterway['ELBE-HAVEL-KANAL'].levels['GENTHIN'])
22
+ end
23
+
24
+ def test_single_measurement
25
+ konstanz_measurements = Waterway['BODENSEE'].levels['KONSTANZ'].measurements
26
+
27
+ assert_equal(Time.parse('2012-09-13 20:00:00 +0200'), konstanz_measurements.last.date)
28
+ assert_equal(380.7, konstanz_measurements.last.value)
29
+ assert_equal(:gleich, konstanz_measurements.last.trend)
17
30
  end
18
31
  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.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: