| 1 | require 'rubygems' |
|---|
| 2 | require 'hpricot' |
|---|
| 3 | |
|---|
| 4 | class AnalyticsXmlParser |
|---|
| 5 | |
|---|
| 6 | def initialize(file) |
|---|
| 7 | @file = file |
|---|
| 8 | end |
|---|
| 9 | |
|---|
| 10 | def parse |
|---|
| 11 | doc = Hpricot.parse(@file.read) |
|---|
| 12 | puts doc.search("//itemsummary[@id='PageviewsSummary']/summaryvalue").first.innerHTML.gsub(',','').to_s |
|---|
| 13 | end |
|---|
| 14 | |
|---|
| 15 | end |
|---|
| 16 | |
|---|
| 17 | file = File.open('/Users/cody/Projects/cakestreet_trunk/tmp/analytics.xml') |
|---|
| 18 | p = AnalyticsXmlParser.new(file) |
|---|
| 19 | p.parse() |
|---|
| 20 | |
|---|
| 21 | =begin |
|---|
| 22 | /Users/cody/Projects/cakestreet_trunk/vendor/rails/railties/lib/commands/runner.rb:47: undefined method `filter[@[=]]' for #<Hpricot::Elem:0x302c350> (NoMethodError) |
|---|
| 23 | from /usr/local/lib/ruby/gems/1.8/gems/hpricot-0.6/lib/hpricot/elements.rb:307:in `filter' |
|---|
| 24 | from /Users/cody/Projects/cakestreet_trunk/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/inflector.rb:250:in `find_all' |
|---|
| 25 | from /usr/local/lib/ruby/gems/1.8/gems/hpricot-0.6/lib/hpricot/elements.rb:305:in `each' |
|---|
| 26 | from /usr/local/lib/ruby/gems/1.8/gems/hpricot-0.6/lib/hpricot/elements.rb:305:in `find_all' |
|---|
| 27 | from /usr/local/lib/ruby/gems/1.8/gems/hpricot-0.6/lib/hpricot/elements.rb:305:in `filter' |
|---|
| 28 | from /usr/local/lib/ruby/gems/1.8/gems/hpricot-0.6/lib/hpricot/traverse.rb:310:in `search' |
|---|
| 29 | from /Users/cody/Projects/cakestreet_trunk/lib/analytics_xml_parser.rb:12:in `parse' |
|---|
| 30 | from /Users/cody/Projects/cakestreet_trunk/lib/analytics_xml_parser.rb:19 |
|---|
| 31 | ... 10 levels... |
|---|
| 32 | from script/runner:3:in `eval' |
|---|
| 33 | from /Users/cody/Projects/cakestreet_trunk/vendor/rails/railties/lib/commands/runner.rb:47 |
|---|
| 34 | from script/runner:3:in `require' |
|---|
| 35 | from script/runner:3 |
|---|
| 36 | =end |
|---|