wasserstand 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +31 -0
- data/Rakefile +10 -0
- data/bin/wasserstand +16 -0
- data/lib/wasserstand/level.rb +18 -0
- data/lib/wasserstand/mapper.rb +39 -0
- data/lib/wasserstand/measurement.rb +17 -0
- data/lib/wasserstand/provider/pegel-online.rb +23 -0
- data/lib/wasserstand/version.rb +3 -0
- data/lib/wasserstand/waterway.rb +16 -0
- data/lib/wasserstand.rb +15 -0
- data/test/fixtures/pegelstaende_neu.xml +6647 -0
- data/test/helper.rb +2 -0
- data/test/unit/test_wasserstand.rb +18 -0
- data/wasserstand.gemspec +22 -0
- metadata +131 -0
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Nicholas E. Rabenau
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Wasserstand
|
2
|
+
|
3
|
+
Unofficial Ruby wrapper for [Pegel Online](http://www.pegelonline.wsv.de/)
|
4
|
+
|
5
|
+
[](http://travis-ci.org/nerab/wasserstand)
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'wasserstand'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install wasserstand
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/bin/wasserstand
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler'
|
4
|
+
Bundler.require
|
5
|
+
|
6
|
+
require 'wasserstand'
|
7
|
+
require 'optparse'
|
8
|
+
|
9
|
+
options = {}
|
10
|
+
OptionParser.new do |opts|
|
11
|
+
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
|
12
|
+
options[:verbose] = v
|
13
|
+
end
|
14
|
+
end.parse!
|
15
|
+
|
16
|
+
puts Wasserstand::Waterway['BODENSEE'].pegel.first.last.messwerte.first
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Wasserstand
|
2
|
+
#
|
3
|
+
# see http://www.pegelonline.wsv.de/gast/hilfe#hilfe_pegelparameter
|
4
|
+
#
|
5
|
+
class Level # Pegel
|
6
|
+
attr_reader :id
|
7
|
+
attr_accessor :name, :km, :measurements
|
8
|
+
|
9
|
+
def initialize(id)
|
10
|
+
@id = id
|
11
|
+
@measurements = []
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_s
|
15
|
+
"#{@name} (km #{@km}): #{@measurements.last}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Wasserstand
|
2
|
+
=begin
|
3
|
+
<gewaesser>
|
4
|
+
<name>BODENSEE</name>
|
5
|
+
<item>
|
6
|
+
<no>8</no>
|
7
|
+
<psmgr>320</psmgr>
|
8
|
+
<pegelname>KONSTANZ</pegelname>
|
9
|
+
<messwert>380,7</messwert>
|
10
|
+
<km>0</km>
|
11
|
+
<pnp>391,89</pnp>
|
12
|
+
<tendenz>Gleich</tendenz>
|
13
|
+
<datum>13.09.2012</datum>
|
14
|
+
<uhrzeit>20:00:00</uhrzeit>
|
15
|
+
<pegelnummer>0906</pegelnummer>
|
16
|
+
</item>
|
17
|
+
</gewaesser>
|
18
|
+
=end
|
19
|
+
class Mapper
|
20
|
+
class << self
|
21
|
+
def map(node)
|
22
|
+
Waterway.new(node.xpath('name').text) .tap do |ww|
|
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
|
26
|
+
pegel.km = item.xpath('km').text
|
27
|
+
|
28
|
+
messdatum = Time.now # TODO parse date from date and time elements
|
29
|
+
wert = item.xpath('messwert').text
|
30
|
+
tendenz = item.xpath('tendenz').text
|
31
|
+
|
32
|
+
pegel.measurements << Measurement.new(messdatum, wert, tendenz)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Wasserstand
|
2
|
+
class Measurement
|
3
|
+
attr_reader :date, :value, :trend
|
4
|
+
|
5
|
+
def initialize(date, value, trend)
|
6
|
+
@date, @value, @trend = date, value, trend
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_i
|
10
|
+
@value
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_s
|
14
|
+
"#{@date}: #{@value} cm, trend #{@trend}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Wasserstand
|
2
|
+
module Provider
|
3
|
+
class PegelOnline
|
4
|
+
def initialize(url = 'http://www.pegelonline.wsv.de/svgz/pegelstaende_neu.xml')
|
5
|
+
@url = url
|
6
|
+
end
|
7
|
+
|
8
|
+
def [](name)
|
9
|
+
doc = Nokogiri::HTML(open(@url).read)
|
10
|
+
results = doc.xpath("//data/table/gewaesser[name/text() = '#{name.upcase}']")
|
11
|
+
|
12
|
+
case results.size
|
13
|
+
when 0
|
14
|
+
return []
|
15
|
+
when 1
|
16
|
+
return Mapper.map(results.first)
|
17
|
+
else
|
18
|
+
raise "Found #{results.size} results for #{name}."
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/wasserstand.rb
ADDED