lightningdb-happymapper 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/happymapper.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{happymapper}
5
- s.version = "0.3.1"
5
+ s.version = "0.3.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["John Nunemaker"]
9
- s.date = %q{2009-01-29}
8
+ s.authors = ["John Nunemaker", "Dave Bolton"]
9
+ s.date = %q{2009-03-17}
10
10
  s.description = %q{object to xml mapping library}
11
11
  s.email = %q{nunemaker@gmail.com}
12
12
  s.extra_rdoc_files = ["lib/happymapper/attribute.rb", "lib/happymapper/element.rb", "lib/happymapper/item.rb", "lib/happymapper/version.rb", "lib/happymapper.rb", "README", "TODO"]
@@ -18,7 +18,7 @@ module HappyMapper
18
18
  self.type = type
19
19
  #self.tag = o.delete(:tag) || name.to_s
20
20
  self.tag = o[:tag] || name.to_s
21
- self.options = o.merge(:name => self.name)
21
+ self.options = { :single => true }.merge(o.merge(:name => self.name))
22
22
 
23
23
  @xml_type = self.class.to_s.split('::').last.downcase
24
24
  end
@@ -120,29 +120,42 @@ module HappyMapper
120
120
  end
121
121
 
122
122
  if element?
123
- result = node.find_first(xpath(namespace))
124
- # puts "vfxn: #{xpath} #{result.inspect}"
125
- if result
126
- value = yield(result)
127
- if options[:attributes].is_a?(Hash)
128
- result.attributes.each do |xml_attribute|
129
- if attribute_options = options[:attributes][xml_attribute.name.to_sym]
130
- attribute_value = Attribute.new(xml_attribute.name.to_sym, *attribute_options).from_xml_node(result, namespace)
131
- result.instance_eval <<-EOV
132
- def value.#{xml_attribute.name}
133
- #{attribute_value.inspect}
134
- end
135
- EOV
136
- end
137
- end
123
+ if options[:single]
124
+ result = node.find_first(xpath(namespace))
125
+ if result
126
+ value = yield(result)
127
+ handle_attributes_option(result,value)
128
+ value
129
+ else
130
+ nil
138
131
  end
139
- value
140
132
  else
141
- nil
133
+ results = node.find(xpath(namespace)).collect do |result|
134
+ value = yield(result)
135
+ handle_attributes_option(result,value)
136
+ value
137
+ end
138
+ results
142
139
  end
143
140
  else
144
141
  yield(node[tag])
145
142
  end
146
143
  end
144
+
145
+ def handle_attributes_option(result, value)
146
+ if options[:attributes].is_a?(Hash)
147
+ result.attributes.each do |xml_attribute|
148
+ if attribute_options = options[:attributes][xml_attribute.name.to_sym]
149
+ attribute_value = Attribute.new(xml_attribute.name.to_sym, *attribute_options).from_xml_node(result, namespace)
150
+ result.instance_eval <<-EOV
151
+ def value.#{xml_attribute.name}
152
+ #{attribute_value.inspect}
153
+ end
154
+ EOV
155
+ end
156
+ end
157
+ end
158
+ end
147
159
  end
148
160
  end
161
+
@@ -2,6 +2,20 @@
2
2
  <familytree xmlns="http://api.familysearch.org/familytree/v1" xmlns:fsapi-v1="http://api.familysearch.org/v1" version="1.0.20071213.942" statusMessage="OK" statusCode="200">
3
3
  <persons>
4
4
  <person version="1199378491000" modified="2008-01-03T09:41:31-07:00" id="KWQS-BBQ">
5
+ <information>
6
+ <alternateIds>
7
+ <id>gedcom.1B5E3087E36D814FA9CBE0BE5B3721EA</id>
8
+ <id>KWQS-BB3</id>
9
+ <id>KWQS-W23</id>
10
+ <id>KWQS-W2S</id>
11
+ <id>KWQS-W29</id>
12
+ <id>KWQM-MMM</id>
13
+ <id>KWQS-W2Q</id>
14
+ <id>KWQS-BBQ</id>
15
+ </alternateIds>
16
+ <gender>Male</gender>
17
+ <living>false</living>
18
+ </information>
5
19
  </person>
6
20
  </persons>
7
- </familytree>
21
+ </familytree>
@@ -35,12 +35,26 @@ class Product
35
35
  end
36
36
 
37
37
  module FamilySearch
38
+ class AlternateIds
39
+ include HappyMapper
40
+
41
+ tag 'alternateIds'
42
+ has_many :ids, String, :tag => 'id'
43
+ end
44
+
45
+ class Information
46
+ include HappyMapper
47
+
48
+ has_one :alternateIds, AlternateIds
49
+ end
50
+
38
51
  class Person
39
52
  include HappyMapper
40
53
 
41
54
  attribute :version, String
42
55
  attribute :modified, Time
43
56
  attribute :id, String
57
+ has_one :information, Information
44
58
  end
45
59
 
46
60
  class Persons
@@ -542,14 +556,16 @@ describe HappyMapper do
542
556
  track.tran_detail.cust_tran_id.should == '20090102-111321'
543
557
  end
544
558
 
545
- xit "should parse family search xml" do
559
+ it "should parse family search xml" do
546
560
  tree = FamilySearch::FamilyTree.parse(fixture_file('family_tree.xml'))
547
561
  tree.version.should == '1.0.20071213.942'
548
562
  tree.status_message.should == 'OK'
549
563
  tree.status_code.should == '200'
550
- # tree.people.size.should == 1
551
- # tree.people.first.version.should == '1199378491000'
552
- # tree.people.first.modified.should == Time.utc(2008, 1, 3, 16, 41, 31) # 2008-01-03T09:41:31-07:00
553
- # tree.people.first.id.should == 'KWQS-BBQ'
564
+ tree.persons.person.size.should == 1
565
+ tree.persons.person.first.version.should == '1199378491000'
566
+ tree.persons.person.first.modified.should == Time.utc(2008, 1, 3, 16, 41, 31) # 2008-01-03T09:41:31-07:00
567
+ tree.persons.person.first.id.should == 'KWQS-BBQ'
568
+ tree.persons.person.first.information.alternateIds.ids.should_not be_kind_of(String)
569
+ tree.persons.person.first.information.alternateIds.ids.size.should == 8
554
570
  end
555
571
  end
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lightningdb-happymapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker
8
+ - Dave Bolton
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
12
 
12
- date: 2009-01-29 00:00:00 -08:00
13
+ date: 2009-03-17 00:00:00 -07:00
13
14
  default_executable:
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency