Class: Wasserstand::PegelOnline::Provider
- Inherits:
-
Object
- Object
- Wasserstand::PegelOnline::Provider
show all
- Defined in:
- lib/wasserstand/provider/pegel-online.rb
Instance Method Summary
collapse
Constructor Details
#initialize(url = 'http://www.pegelonline.wsv.de/svgz/pegelstaende_neu.xml') ⇒ Provider
Returns a new instance of Provider.
4
5
6
|
# File 'lib/wasserstand/provider/pegel-online.rb', line 4
def initialize(url = 'http://www.pegelonline.wsv.de/svgz/pegelstaende_neu.xml')
@url = url
end
|
Instance Method Details
#[](name) ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/wasserstand/provider/pegel-online.rb', line 8
def [](name)
results = doc.xpath(xpath_lookup(name))
case results.size
when 0
return nil when 1
return mapper.map(results.first)
else
raise "Name is not unique. Found #{results.size} results for #{name}."
end
end
|
#all ⇒ Object
21
22
23
|
# File 'lib/wasserstand/provider/pegel-online.rb', line 21
def all
doc.xpath(xpath_all).map{|o| mapper.map(o)}
end
|
#find_by_name(name_expression) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/wasserstand/provider/pegel-online.rb', line 25
def find_by_name(name_expression)
doc.xpath(xpath_finder(name_expression), Class.new{
def matches(node_set, regex)
node_set.find_all do |node|
node.to_s.match(%r{#{regex}})
end
end
}.new).map{|o| mapper.map(o)}
end
|