wasserstand 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/TODO +3 -0
- data/bin/wasserstand +54 -4
- data/lib/wasserstand.rb +11 -1
- data/lib/wasserstand/finders.rb +1 -0
- data/lib/wasserstand/hash_clod.rb +9 -7
- data/lib/wasserstand/heap_cache.rb +14 -12
- data/lib/wasserstand/measurement.rb +1 -1
- data/lib/wasserstand/provider/pegel_online.rb +1 -1
- data/lib/wasserstand/version.rb +1 -1
- data/wasserstand.gemspec +2 -0
- metadata +19 -1
data/README.md
CHANGED
data/TODO
ADDED
data/bin/wasserstand
CHANGED
@@ -6,11 +6,61 @@ Bundler.require
|
|
6
6
|
require 'wasserstand'
|
7
7
|
require 'optparse'
|
8
8
|
|
9
|
-
options = {}
|
10
9
|
OptionParser.new do |opts|
|
11
|
-
opts.
|
12
|
-
|
10
|
+
opts.banner = <<HERE
|
11
|
+
Wasserstand provides water level information as provided by PegelOnline.
|
12
|
+
|
13
|
+
Usage:
|
14
|
+
#{File.basename($0)} [options] [WATERWAY | LEVEL]
|
15
|
+
|
16
|
+
Author:
|
17
|
+
Nicolas E. Rabenau nerab@gmx.at
|
18
|
+
|
19
|
+
Homepage:
|
20
|
+
http://github.com/nerab/wasserstand
|
21
|
+
|
22
|
+
Options:
|
23
|
+
HERE
|
24
|
+
|
25
|
+
opts.on("-w", "--verbose", "Run verbosely") do |v|
|
26
|
+
Wasserstand.logger.level = Log4r::INFO
|
27
|
+
Wasserstand.logger.info("Enable info logger")
|
28
|
+
end
|
29
|
+
|
30
|
+
opts.on("-t", "--trace", "Run with traces enabled") do |v|
|
31
|
+
Wasserstand.logger.level = Log4r::ALL
|
32
|
+
Wasserstand.logger.debug("Enable debug logger")
|
33
|
+
end
|
34
|
+
|
35
|
+
opts.on("-u", "--url URL", "Use URL to fetch levels") do |url|
|
36
|
+
Wasserstand.logger.info("Using URL #{url}")
|
37
|
+
Wasserstand.provider = Wasserstand::Provider::PegelOnline.new(url)
|
13
38
|
end
|
14
39
|
end.parse!
|
15
40
|
|
16
|
-
|
41
|
+
query = ARGV.shift
|
42
|
+
|
43
|
+
if query.nil?
|
44
|
+
Wasserstand::Waterway.all.each{|ww| puts "#{ww.name} (#{ww.levels.size} levels)"}
|
45
|
+
else
|
46
|
+
begin
|
47
|
+
waterway = Wasserstand::Waterway[query]
|
48
|
+
|
49
|
+
if waterway
|
50
|
+
puts "#{waterway.name} has #{waterway.levels.size} levels:"
|
51
|
+
waterway.levels.sort_by{|name, level| level.km}.each{|name, level| puts "#{name} (km #{level.km}): #{level.measurements.last}"}
|
52
|
+
else
|
53
|
+
level = Wasserstand::Level[query]
|
54
|
+
|
55
|
+
if level.nil?
|
56
|
+
STDERR.puts "#{File.basename($0)}: No waterway nor level found that matches '#{query}."
|
57
|
+
else
|
58
|
+
puts "Level #{level.name} (#{level.waterway}, km #{level.km}):"
|
59
|
+
level.measurements.each{|measurement| puts measurement}
|
60
|
+
end
|
61
|
+
end
|
62
|
+
rescue
|
63
|
+
STDERR.puts $!
|
64
|
+
$!.backtrace.each{|msg| Wasserstand.logger.debug(msg)}
|
65
|
+
end
|
66
|
+
end
|
data/lib/wasserstand.rb
CHANGED
@@ -4,8 +4,9 @@ require 'tzinfo'
|
|
4
4
|
require 'unicode_utils/upcase'
|
5
5
|
require 'unicode_utils/downcase'
|
6
6
|
require 'forwardable'
|
7
|
-
|
7
|
+
require 'log4r'
|
8
8
|
require 'require_all'
|
9
|
+
|
9
10
|
require_rel 'wasserstand'
|
10
11
|
|
11
12
|
module Wasserstand
|
@@ -17,5 +18,14 @@ module Wasserstand
|
|
17
18
|
def provider
|
18
19
|
@provider ||= Provider::PegelOnline.new
|
19
20
|
end
|
21
|
+
|
22
|
+
def logger
|
23
|
+
@logger ||= Log4r::Logger.new(self.name).tap do |logger|
|
24
|
+
out = Log4r::Outputter.stderr
|
25
|
+
out.formatter = Log4r::PatternFormatter.new(:pattern => "%l: %m")
|
26
|
+
logger.outputters = out
|
27
|
+
logger.level = Log4r::WARN
|
28
|
+
end
|
29
|
+
end
|
20
30
|
end
|
21
31
|
end
|
data/lib/wasserstand/finders.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
module Wasserstand
|
2
|
+
# http://stackoverflow.com/questions/2030336/how-do-i-create-a-hash-in-ruby-that-compares-strings-ignoring-case
|
3
|
+
class HashClod < Hash
|
4
|
+
def [](key)
|
5
|
+
key.respond_to?(:upcase) ? super(UnicodeUtils.upcase(key)) : super(key)
|
6
|
+
end
|
6
7
|
|
7
|
-
|
8
|
-
|
8
|
+
def []=(key, value)
|
9
|
+
key.respond_to?(:upcase) ? super(UnicodeUtils.upcase(key), value) : super(key, value)
|
10
|
+
end
|
9
11
|
end
|
10
12
|
end
|
@@ -1,16 +1,18 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module Wasserstand
|
2
|
+
class HeapCache
|
3
|
+
def initialize
|
4
|
+
@backend = {}
|
5
|
+
end
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
def get(name)
|
8
|
+
result = @backend[name]
|
9
|
+
Wasserstand.logger.debug "#{self.class.name} GET #{result ? 'HIT' : 'MISS'} #{name}"
|
10
|
+
result
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
def set(name, value)
|
14
|
+
Wasserstand.logger.debug "#{self.class.name} SET #{name} => #{value.inspect}"
|
15
|
+
@backend[name] = value
|
16
|
+
end
|
15
17
|
end
|
16
18
|
end
|
@@ -44,7 +44,7 @@ module Wasserstand
|
|
44
44
|
#
|
45
45
|
def replenish
|
46
46
|
@names.clear
|
47
|
-
|
47
|
+
Wasserstand.logger.info "Fetching #{@url}"
|
48
48
|
doc = Nokogiri::HTML(open(@url).read, nil, 'ISO-8859-1')
|
49
49
|
doc.xpath("//data/table/gewaesser").each do |node|
|
50
50
|
ww = WaterwayMapper.map(node)
|
data/lib/wasserstand/version.rb
CHANGED
data/wasserstand.gemspec
CHANGED
@@ -19,6 +19,8 @@ Gem::Specification.new do |gem|
|
|
19
19
|
gem.add_runtime_dependency 'nokogiri'
|
20
20
|
gem.add_runtime_dependency 'tzinfo'
|
21
21
|
gem.add_runtime_dependency 'unicode_utils'
|
22
|
+
gem.add_runtime_dependency 'log4r'
|
23
|
+
|
22
24
|
gem.add_development_dependency 'minitest'
|
23
25
|
gem.add_development_dependency 'rake'
|
24
26
|
gem.add_development_dependency 'pry'
|
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.10
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -75,6 +75,22 @@ dependencies:
|
|
75
75
|
- - ! '>='
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: log4r
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
78
94
|
- !ruby/object:Gem::Dependency
|
79
95
|
name: minitest
|
80
96
|
requirement: !ruby/object:Gem::Requirement
|
@@ -171,6 +187,7 @@ files:
|
|
171
187
|
- LICENSE
|
172
188
|
- README.md
|
173
189
|
- Rakefile
|
190
|
+
- TODO
|
174
191
|
- bin/wasserstand
|
175
192
|
- lib/wasserstand.rb
|
176
193
|
- lib/wasserstand/finders.rb
|
@@ -222,3 +239,4 @@ test_files:
|
|
222
239
|
- test/unit/test_measurement.rb
|
223
240
|
- test/unit/test_trend.rb
|
224
241
|
- test/unit/test_waterway.rb
|
242
|
+
has_rdoc:
|