wasserstand 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/lib/wasserstand.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'nokogiri'
2
2
  require 'open-uri'
3
3
  require 'tzinfo'
4
+ require 'unicode_utils/upcase'
4
5
 
5
6
  require 'require_all'
6
7
  require_rel 'wasserstand'
@@ -6,7 +6,6 @@ module Wasserstand
6
6
  end
7
7
 
8
8
  def [](name)
9
- doc = Nokogiri::HTML(fetch(@url), nil, 'ISO-8859-1')
10
9
  results = doc.xpath(xpath_lookup(name))
11
10
 
12
11
  case results.size
@@ -20,13 +19,13 @@ module Wasserstand
20
19
  end
21
20
 
22
21
  def all
23
- Nokogiri::HTML(fetch(@url), nil, 'ISO-8859-1').xpath(xpath_all).map{|o| mapper.map(o)}
22
+ doc.xpath(xpath_all).map{|o| mapper.map(o)}
24
23
  end
25
24
 
26
25
  def find_by_name(name_expression)
27
26
  # Not the best performing way, but it gives us the ability to use the XPath 2.0 'matches' function
28
27
  # which isn't supported in Nokogiri (yet).
29
- Nokogiri::HTML(fetch(@url), nil, 'ISO-8859-1').xpath(xpath_finder(name_expression), Class.new{
28
+ doc.xpath(xpath_finder(name_expression), Class.new{
30
29
  def matches(node_set, regex)
31
30
  node_set.find_all do |node|
32
31
  node.to_s.match(%r{#{regex}})
@@ -38,7 +37,7 @@ module Wasserstand
38
37
  protected
39
38
 
40
39
  def xpath_lookup(name)
41
- "#{xpath_all}[#{name_attribute}/text() = '#{name.upcase}']"
40
+ "#{xpath_all}[#{name_attribute}/text() = '#{UnicodeUtils.upcase(name)}']"
42
41
  end
43
42
 
44
43
  def xpath_finder(regex)
@@ -52,6 +51,12 @@ module Wasserstand
52
51
  def name_attribute
53
52
  'name'
54
53
  end
54
+
55
+ private
56
+
57
+ def doc
58
+ Nokogiri::HTML(fetch(@url), nil, 'ISO-8859-1')
59
+ end
55
60
  end
56
61
 
57
62
  class WaterwayProvider < Provider
@@ -1,3 +1,3 @@
1
1
  module Wasserstand
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -2,11 +2,11 @@ module Wasserstand
2
2
  # http://stackoverflow.com/questions/2030336/how-do-i-create-a-hash-in-ruby-that-compares-strings-ignoring-case
3
3
  class HashClod < Hash
4
4
  def [](key)
5
- key.respond_to?(:upcase) ? super(key.upcase) : super(key)
5
+ key.respond_to?(:upcase) ? super(UnicodeUtils.upcase(key)) : super(key)
6
6
  end
7
7
 
8
8
  def []=(key, value)
9
- key.respond_to?(:upcase) ? super(key.encode.upcase, value) : super(key, value)
9
+ key.respond_to?(:upcase) ? super(UnicodeUtils.upcase(key), value) : super(key, value)
10
10
  end
11
11
  end
12
12
 
data/test/helper.rb CHANGED
@@ -7,5 +7,6 @@ class WasserstandTestCase < MiniTest::Unit::TestCase
7
7
  def setup
8
8
  url = File.join(File.dirname(__FILE__), 'fixtures', 'pegelstaende_neu.xml')
9
9
  Wasserstand.waterway_provider = PegelOnline::WaterwayProvider.new(url)
10
+ Wasserstand.level_provider = PegelOnline::LevelProvider.new(url)
10
11
  end
11
12
  end
@@ -1,3 +1,4 @@
1
+ # -*- encoding: utf-8 -*-
1
2
  require 'helper'
2
3
 
3
4
  class TestWaterway < WasserstandTestCase
@@ -18,4 +19,9 @@ class TestWaterway < WasserstandTestCase
18
19
  assert(Waterway['Elbe'].levels['Pirna'])
19
20
  assert(Waterway['ELBE-HAVEL-KANAL'].levels['GENTHIN'])
20
21
  end
22
+
23
+ def test_lookup_umlaut
24
+ assert(Waterway['Küstenkanal'])
25
+ assert(Waterway['Elbe'].levels['Schöna'])
26
+ end
21
27
  end
data/wasserstand.gemspec CHANGED
@@ -18,6 +18,7 @@ Gem::Specification.new do |gem|
18
18
  gem.add_runtime_dependency 'require_all'
19
19
  gem.add_runtime_dependency 'nokogiri'
20
20
  gem.add_runtime_dependency 'tzinfo'
21
+ gem.add_runtime_dependency 'unicode_utils'
21
22
  gem.add_development_dependency 'minitest'
22
23
  gem.add_development_dependency 'rake'
23
24
  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.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-16 00:00:00.000000000 Z
12
+ date: 2012-09-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: require_all
@@ -59,6 +59,22 @@ dependencies:
59
59
  - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: unicode_utils
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
62
78
  - !ruby/object:Gem::Dependency
63
79
  name: minitest
64
80
  requirement: !ruby/object:Gem::Requirement