noaa
noaa copied to clipboard
undefined method `xpath' for LibXML::XML
Using Ruby 1.9.1 Using libxml-ruby 2.0.9
weather = NOAA.current_conditions_at_station("KCAK")
weather.weather_description
NoMethodError: undefined method `xpath' for #<LibXML::XML::Document:0x00000107379418>
from /Users/skibler/Projects/newscloudcms/.bundle/ruby/1.9.1/gems/noaa-0.2.4/lib/noaa/current_conditions.rb:177:in `text_from_node'
from /Users/skibler/Projects/newscloudcms/.bundle/ruby/1.9.1/gems/noaa-0.2.4/lib/noaa/current_conditions.rb:30:in `weather_description'
from (irb):6
from /Users/skibler/Projects/newscloudcms/.bundle/ruby/1.9.1/gems/railties-3.0.3/lib/rails/commands/console.rb:44:in `start'
from /Users/skibler/Projects/newscloudcms/.bundle/ruby/1.9.1/gems/railties-3.0.3/lib/rails/commands/console.rb:8:in `start'
from /Users/skibler/Projects/newscloudcms/.bundle/ruby/1.9.1/gems/railties-3.0.3/lib/rails/commands.rb:23:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
$ ruby -v ruby 1.8.7 (2011-02-18 patchlevel 334) [x86_64-linux]
$ ~/bin/oxfordWeatherAll.rb
/usr/local/lib64/ruby/gems/1.8/gems/noaa-0.2.4/lib/noaa/current_conditions.rb:177:in text_from_node': undefined method
xpath' for #LibXML::XML::Document:0x7f0026190de8 (NoMethodError)
from /usr/local/lib64/ruby/gems/1.8/gems/noaa-0.2.4/lib/noaa/current_conditions.rb:23:in `observed_at'
from /home/rthompso/bin/oxfordWeatherAll.rb:19
$ gem list --local
*** LOCAL GEMS ***
andre-geokit (1.5.0) atk (0.19.4) cairo (1.10.0) color (1.4.1) columnize (0.3.4) daemons (1.1.3) echoe (4.3.1) fastthread (1.0.7) gdkpixbuf2 (0.19.4) geokit (1.6.0) gettext (2.1.0) glib2 (0.19.4) gnome2 (0.19.4) gnomecanvas2 (0.19.4) gruff (0.3.6) gtk2 (0.19.4) highline (1.6.1) hoe (2.8.0) httparty (0.8.1) httpclient (2.2.1) jeremymcanally-context (0.5.5) jeremymcanally-matchy (0.1.0) json (1.4.6) libart2 (0.19.4) libglade2 (0.19.4) libxml-ruby (2.2.2) linecache (0.46) locale (2.0.5) multi_json (1.0.3) multi_xml (0.4.1) net-http-digest_auth (1.1.1) net-http-persistent (2.1) net-scp (1.0.4) net-sftp (2.0.5) net-ssh (2.1.3) noaa (0.2.4) nokogiri (1.5.0) outoftime-noaa (0.2.2) pango (0.19.4) pdf-writer (1.1.8) rake (0.8.7) rake-compiler (0.7.5) rbx-require-relative (0.0.5) rmagick (2.13.0) ruby-debug (0.10.4) ruby-debug-base (0.10.4) ruby-net-ldap (0.0.4) ruby-prof (0.10.7) rubyforge (2.0.4) rubygems-update (1.8.10 ruby) RubyInline (3.8.6) sqlite3-ruby (1.3.2) syntax (1.0.0) transaction-simple (1.4.0) xml-simple (1.1.0) ZenTest (4.4.2)
fixed for my purposed by changing line 177 of current_conditions.rb from #@doc.xpath("/current_observation/#{element_name}[1]/child::text()").first.to_s to @doc.find("/current_observation/#{element_name}[1]/child::text()").first.to_s
/usr/local/lib64/ruby/gems/1.8/gems/noaa-0.2.4/lib/noaa/current_conditions.rb:177:in text_from_node': undefined method
xpath' for #LibXML::XML::Document:0x7fe21411e8f8 (NoMethodError
it appears that current_conditions.rb line 177 def text_from_node(element_name) @doc.xpath("/current_observation/#{element_name}[1]/child::text()").first.to_s end should now read as def text_from_node(element_name) @doc.find("/current_observation/#{element_name}[1]/child::text()").first.to_s end