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 +1 -0
- data/happymapper.gemspec +1 -1
- data/lib/happymapper.rb +8 -7
- data/lib/happymapper/version.rb +1 -1
- data/spec/happymapper_spec.rb +46 -0
- metadata +1 -1
data/Manifest
CHANGED
data/happymapper.gemspec
CHANGED
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.
|
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')
|
data/lib/happymapper/version.rb
CHANGED
data/spec/happymapper_spec.rb
CHANGED
@@ -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'
|