Class: Wasserstand::Provider::PegelOnline
- Inherits:
-
Object
- Object
- Wasserstand::Provider::PegelOnline
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/wasserstand/provider/pegel_online.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#initialize(url = 'http://www.pegelonline.wsv.de/svgz/pegelstaende_neu.xml') ⇒ PegelOnline
constructor
A new instance of PegelOnline.
- #levels ⇒ Object
-
#waterways ⇒ Object
Cache entries may expire, and simply iterating over the list of current cache entries would render an incomplete picture.
Constructor Details
#initialize(url = 'http://www.pegelonline.wsv.de/svgz/pegelstaende_neu.xml') ⇒ PegelOnline
Returns a new instance of PegelOnline.
10 11 12 13 |
# File 'lib/wasserstand/provider/pegel_online.rb', line 10 def initialize(url = 'http://www.pegelonline.wsv.de/svgz/pegelstaende_neu.xml') @url = url @names = [] end |
Instance Attribute Details
Instance Method Details
#levels ⇒ Object
32 33 34 |
# File 'lib/wasserstand/provider/pegel_online.rb', line 32 def levels waterways.inject([]){|result, ww| result.concat(ww.levels.values)} end |
#waterways ⇒ Object
Cache entries may expire, and simply iterating over the list of current cache entries would render an incomplete picture. Therefore we maintain the knowledge of what waterways exist in a single list, which is the authoritative source of what waterways exist.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/wasserstand/provider/pegel_online.rb', line 16 def waterways replenish if @names.empty? @names.map do |name| ww = cache.get(name) # no fetch with block in Dalli, so we cannot use it here either ... # Not finding the Waterway for a name means it was removed from the cache, but it may or may not exist in the backend. Therefore we need to replenish our cache including our knowledge about the name. if ww.nil? replenish ww = cache.get(name) # Still nil? Does not matter. Replenish has auto-removed an outdated name. end ww end.compact # don't return nil entries end |