jnunemaker-happymapper 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest CHANGED
@@ -15,6 +15,7 @@ Manifest
15
15
  Rakefile
16
16
  README
17
17
  spec/fixtures/address.xml
18
+ spec/fixtures/analytics.xml
18
19
  spec/fixtures/commit.xml
19
20
  spec/fixtures/current_weather.xml
20
21
  spec/fixtures/family_tree.xml
data/happymapper.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{happymapper}
5
- s.version = "0.2.3"
5
+ s.version = "0.2.4"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["John Nunemaker"]
data/lib/happymapper.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  dir = File.dirname(__FILE__)
2
- $:.unshift(dir) unless $:.include?(dir) || $:.include?(File.expand_path(dir))
3
2
 
4
3
  require 'date'
5
4
  require 'time'
@@ -86,14 +85,16 @@ module HappyMapper
86
85
  # namespace prefix registered here will propagate down
87
86
  namespaces = node.namespaces
88
87
  if namespaces && namespaces.default
89
- namespaces.default_prefix = DEFAULT_NS
88
+ already_assigned = namespaces.definitions.detect do |defn|
89
+ namespaces.default && namespaces.default.href == defn.href && defn.prefix
90
+ end
91
+ namespaces.default_prefix = DEFAULT_NS unless already_assigned
90
92
  namespace ||= DEFAULT_NS
91
93
  end
92
94
 
93
95
  xpath = root ? '/' : './/'
94
96
  xpath += "#{namespace}:" if namespace
95
97
  xpath += tag_name
96
- # puts "parse: #{xpath}"
97
98
 
98
99
  nodes = node.find(xpath)
99
100
  collection = nodes.collect do |n|
@@ -108,7 +109,7 @@ module HappyMapper
108
109
  obj.send("#{elem.method_name}=",
109
110
  elem.from_xml_node(n, namespace))
110
111
  end
111
-
112
+
112
113
  obj
113
114
  end
114
115
 
@@ -124,6 +125,6 @@ module HappyMapper
124
125
  end
125
126
  end
126
127
 
127
- require 'happymapper/item'
128
- require 'happymapper/attribute'
129
- require 'happymapper/element'
128
+ require File.join(dir, 'happymapper/item')
129
+ require File.join(dir, 'happymapper/attribute')
130
+ require File.join(dir, 'happymapper/element')
@@ -1,3 +1,3 @@
1
1
  module HappyMapper
2
- Version = '0.2.3'
2
+ Version = '0.2.4'
3
3
  end
@@ -2,6 +2,38 @@ require File.dirname(__FILE__) + '/spec_helper.rb'
2
2
  require 'pp'
3
3
  require 'uri'
4
4
 
5
+ module Analytics
6
+ class Property
7
+ include HappyMapper
8
+
9
+ tag 'property'
10
+ namespace 'dxp'
11
+ attribute :name, String
12
+ attribute :value, String
13
+ end
14
+
15
+ class Entry
16
+ include HappyMapper
17
+
18
+ tag 'entry'
19
+ element :id, String
20
+ element :updated, DateTime
21
+ element :title, String
22
+ element :table_id, String, :namespace => 'dxp', :tag => 'tableId'
23
+ has_many :properties, Property
24
+ end
25
+
26
+ class Feed
27
+ include HappyMapper
28
+
29
+ tag 'feed'
30
+ element :id, String
31
+ element :updated, DateTime
32
+ element :title, String
33
+ has_many :entries, Entry
34
+ end
35
+ end
36
+
5
37
  class Feature
6
38
  include HappyMapper
7
39
  element :name, String, :tag => '.|.//text()'
@@ -505,6 +537,20 @@ describe HappyMapper do
505
537
  track.tran_detail.cust_tran_id.should == '20090102-111321'
506
538
  end
507
539
 
540
+ it "should be able to parse google analytics api xml" do
541
+ data = Analytics::Feed.parse(fixture_file('analytics.xml'))
542
+ data.id.should == 'http://www.google.com/analytics/feeds/accounts/nunemaker@gmail.com'
543
+ data.entries.size.should == 4
544
+
545
+ entry = data.entries[0]
546
+ entry.title.should == 'addictedtonew.com'
547
+ entry.properties.size.should == 4
548
+
549
+ property = entry.properties[0]
550
+ property.name.should == 'ga:accountId'
551
+ property.value.should == '85301'
552
+ end
553
+
508
554
  xit "should parse family search xml" do
509
555
  tree = FamilySearch::FamilyTree.parse(fixture_file('family_tree.xml'))
510
556
  tree.version.should == '1.0.20071213.942'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jnunemaker-happymapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker